Sunday, May 2, 2010

Highlight PowerShell in red when running as Administrator

If you have the PowerShell Community Extensions installed, you can load your profile for editing by running notepad $profile or ep.

Paste the code from this blog into your profile:
& {
    $wid=[System.Security.Principal.WindowsIdentity]::GetCurrent()
    $prp=new-object System.Security.Principal.WindowsPrincipal($wid)
    $adm=[System.Security.Principal.WindowsBuiltInRole]::Administrator
    $IsAdmin=$prp.IsInRole($adm)
    if ($IsAdmin)
    {
        (get-host).UI.RawUI.Backgroundcolor="DarkRed"
        clear-host
    }
}

If you are running all users as standard users (which you should really be doing, see why here), there is no need to use this script. Simply put the following code into the Administrator profile:
(get-host).UI.RawUI.Backgroundcolor="DarkRed"
clear-host

0 comments:

Post a Comment