Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Verify the user running the script is a local admin before proceeding
[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
You can’t perform that action at this time.