Last active
December 14, 2015 19:09
-
-
Save rpunt/5134907 to your computer and use it in GitHub Desktop.
Verify the user running the script is a local admin before proceeding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[CmdletBinding()] | |
param ( | |
[parameter(Mandatory=$true)][string]$adminuser, | |
[parameter(Mandatory=$true)][string]$adminpassword | |
) | |
$computer = gc env:computername | |
# did you enter valid credentials for a local user? | |
[Reflection.Assembly]::LoadFile('C:\Windows\assembly\GAC_MSIL\System.DirectoryServices\2.0.0.0__b03f5f7f11d50a3a\System.DirectoryServices.dll') | |
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