Thursday, April 24, 2008

Powershell Prompt

With my recent re-dedication to working with UAC, I find myself constantly wondering if I'm running Powershell in Admin mode not. After a little poking around, I found that the "SESSIONNAME" environment variable is missing when running as an administrator. Odd, but whatever. The upside of this is, I can now tell if I'm running in Admin mode and throw up a different prompt. So! Here is my new, revised Prompt function for Powershell:


function Prompt
{
  if (($env:SESSIONNAME).Length -gt 0)
  {
    $host.ui.RawUI.WindowTitle = $(get-location)
    "$>"
  }
  else
  {
    $host.ui.RawUI.WindowTitle = '[Admin] ' + $(get-location)
    "#>"
  }
}

No comments: