search
Categories
Sponsors
VirtualMetric Hyper-V Monitoring, Hyper-V Reporting
Archive
Blogroll

Badges
MCSE
Community

Cozumpark Bilisim Portali
Checking Administrator Privileges on Powershell
Posted in Windows Powershell | No Comment | 1,478 views | 14/07/2012 21:49

Your script needs “Run as Administrator” privileges? Then you should use this function to check it.

1
2
3
4
5
6
7
8
9
function Confirm-PoSHAdminPrivileges
{
	$User = [Security.Principal.WindowsIdentity]::GetCurrent()
	if((New-Object Security.Principal.WindowsPrincipal $User).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator))
	{
		$Result = "Validated"
	}
	$Result
}

If you get “Validated” as a output, then you can be sure about administrator privileges.



Leave a Reply