Customizing the powershell prompt

Опубликовано: 24 Июнь 2026
на канале: Said Mousa Sajadi
12
0

$PSVersionTable

Set-ExecutionPolicy RemoteSigned


$Profile

Test-Path $Profile

New-Item -Path $Profile -Type File -Force

-------------------------
clear ;
function Prompt {
$Global:Admin=' $' ;
$CurrentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent() ;
$principal = new-object System.Security.principal.windowsprincipal($CurrentUser) ;
if ($principal.IsInRole("Administrators")) { $Admin=' #' } ;

write-host "$env:UserName" -ForeGroundColor Red -NoNewLine ;
write-host "@" -ForeGroundColor Magenta -NoNewLine ;
write-host "$env:ComputerName" -ForeGroundColor Red -NoNewLine ;
write-host " $(get-location)" -ForeGroundColor Green -NoNewLine ;
write-host $Admin -ForeGroundColor Magenta -NoNewLine ;
" "}