Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Verify the user running the script is a local admin before proceeding
param (
$computer = gc env:computername
# did you enter valid credentials for a local user?
Add-Type -assemblyname system.DirectoryServices.accountmanagement
$DS = New-Object System.DirectoryServices.AccountManagement.PrincipalContext([System.DirectoryServices.AccountManagement.ContextType]::Machine)
if ($DS.ValidateCredentials($adminuser, $adminpassword)) {
# yay!
} else {
# boo!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment