StevensNet.com

...Because someone's gotta tell the story...

Blogs

To return to the main Blog List, click Full Blog Listing.

Tags

PowerShell
SMB
Windows

Powershell: Checking elevated credentials

Thursday, April 18, 2013 in Powershell (Views: 1864)
Another quickie this morning, for those who run scripts but forget that nasty UAC to run as an elevated / admin credential.

Insert this into your script to test for the admin credentials...

If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
[Security.Principal.WindowsBuiltInRole] "Administrator"))
{
Write-Host "This script is not running with elevated credentials.`nPlease launch with Admin credentials."
Break
}

 

Related Blogs You May Be Interested In:


To leave a comment, please log in and/or register.