Skip to content

Instantly share code, notes, and snippets.

@roberttoups
Created November 24, 2020 16:26
Show Gist options
  • Save roberttoups/fdb0b880f51ebcd10f2f40c1cfcff4d9 to your computer and use it in GitHub Desktop.
Save roberttoups/fdb0b880f51ebcd10f2f40c1cfcff4d9 to your computer and use it in GitHub Desktop.
Upgraded PowerShell Profile Prompt
function prompt {
if(([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
if($env:USERDNSDOMAIN) {
Write-Host "$($env:USERNAME)@$($env:USERDNSDOMAIN)" -NoNewline -ForegroundColor 'Red'
Write-Host "(ELEVATED)" -NoNewline -ForegroundColor 'White'
Write-Host ":" -NoNewline -ForegroundColor 'DarkGray'
Write-Host "[$($env:COMPUTERNAME)]" -NoNewline -ForegroundColor 'Yellow'
} else {
Write-Host "$($env:USERNAME)@$($env:COMPUTERNAME)" -NoNewline -ForegroundColor 'Red'
Write-Host "(ELEVATED)" -NoNewline -ForegroundColor 'White'
}
} else {
if($env:USERDNSDOMAIN) {
Write-Host "$($env:USERNAME)@$($env:USERDNSDOMAIN)" -NoNewline -ForegroundColor 'Yellow'
Write-Host ":" -NoNewline -ForegroundColor 'DarkGray'
Write-Host "[$($env:COMPUTERNAME)]" -NoNewline -ForegroundColor 'Yellow'
} else {
Write-Host "$($env:USERNAME)@$($env:COMPUTERNAME)" -NoNewline -ForegroundColor 'Yellow'
}
}
Write-Host ":" -NoNewline -ForegroundColor 'DarkGray'
Write-Host (Get-Date -Format G) -ForegroundColor 'Yellow'
Write-Host "[" -NoNewline -ForegroundColor Red
$CurrentPath = $ExecutionContext.SessionState.Path.CurrentLocation.Path
$CurrentPath = $CurrentPath.Replace($HOME, '~')
Write-Host $CurrentPath -NoNewline -ForegroundColor 'Green'
Write-Host "]" -ForegroundColor 'Red'
return "$('PS >' * ($nestedPromptLevel + 1)) "
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment