maphew

Powershell profile prompt

 

Powershell: use red # instead of > to indicate when in an Administrator elevated shell. 

function prompt {
    $user = [Security.Principal.WindowsIdentity]::GetCurrent()
    $isAdmin = (New-Object Security.Principal.WindowsPrincipal $user).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)

    $redHash = "$([char]27)[31m# $([char]27)[0m"  # red '#' then reset
    $location = Get-Location
    $nest = if ($NestedPromptLevel -ge 1) { '##' } else { '' }

    if ($isAdmin) {
        " PS $location$nest$redHash"
    } else {
        " PS $location$nest$redHash"
    }
}

 

Edit the profile:

notepad $profile

Load it:

. $profile