Here's a simple way to tell if you're running as an administrator from within PowerShell:
$windowsIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent() $windowsPrincipal = new-object 'System.Security.Principal.WindowsPrincipal' $windowsIdentity return $windowsPrincipal.IsInRole("Administrators")
I like to use this right at the top of my startup profile to turn my window background dark red:
if ((get-isadmin) -and (-not $psISE)) { $Host.UI.RawUI.BackgroundColor = "DarkRed" clear }
Since the raw UI can only use colors from the console, I also tweak my console's interpretation of dark red into (48,0,0) so that it's very dark, nearly black but still recognizably red. I also change my prompt color from green to yellow. It's very obvious looking at green on black vs. yellow on red that I'm in an admin prompt.
I check to make sure we're not running in the ISE, because the ISE runs a dark on light color scheme and doesn't paint the same way as the console version of PowerShell.
Recent Comments