Friday, November 19, 2010

PowerShell Profile

Some handy functions I put into my PowerShell profile.

#Change background colour of window if PowerShell is launched "As Administrator" under UAC
& {
    $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
    }
}

#Create an alias 'ed' to launch Visual Studio as your file editor
function Edit-WithDevenv([string]$Path)
{
    & devenv /edit $Path 
}
new-alias ed edit-withdevenv

0 comments:

Post a Comment