Admin Privileges Enabled?

If you want to know whether your script has currently full Administrator privileges, here is an (admittedly long) one-liner that tells you:

(New-Object System.Security.Principal.WindowsPrincipal([System.Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)

Try executing this line in a regular PowerShell and then in an elevated shell, and check out the difference. Or, create your own console prompt which turns red when you have admin privileges:

function prompt {
if ((New-Object System.Security.Principal.WindowsPrincipal([System.Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)) {
  Write-Host (Admin) ForegroundColor Red -NoNewLine
  $user = Administrator: 
} else {
  $user = ‘’
}
PS> 
$Host.UI.RawUI.WindowTitle = $user $(Get-Location)
}

Twitter This Tip! ReTweet this Tip!


Posted Feb 16 2012, 06:00 AM by ps1

Comments

B. T. wrote re: Admin Privileges Enabled?
on 02-24-2012 1:58 PM

I can't see all of the code because the code is chopped off.

Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.