Skip to content

Instantly share code, notes, and snippets.

@chelnak
Created June 24, 2019 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chelnak/10408a635f1f7cb0ff9b7631d81af9e3 to your computer and use it in GitHub Desktop.
Save chelnak/10408a635f1f7cb0ff9b7631d81af9e3 to your computer and use it in GitHub Desktop.
Custom prompt for PowerShell that displays your current Az subscription in the tile bar
function Prompt {
$CurrentTitle = $Host.UI.RawUI.WindowTitle
$Host.UI.RawUI.WindowTitle = "Loading Az ..."
Set-Location -Path $ENV:USERPROFILE/code -ErrorAction stop
$IsElevated = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
if ($IsElevated) {
Write-Host "$([char]9788) " -ForegroundColor Red -NoNewline
}else {
Write-Host "$([char]9788) " -ForegroundColor Yellow -NoNewline
}
Write-Host 'Craig ' -ForegroundColor Green -NoNewline
Write-Host "[$((Get-Location).path)]" -NoNewline
Write-Host
Write-Output '# '
$SubScriptionName = (Get-AzContext).Subscription.Name
if ($SubScriptionName) {
$WindowTitle = "PowerShell | Az - [$($SubscriptionName)]"
} else {
$WindowTitle = $CurrentTitle
}
$Host.UI.RawUI.WindowTitle = $WindowTitle
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment