Created
June 24, 2019 21:10
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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