Skip to content

Instantly share code, notes, and snippets.

@rpunt
Last active December 14, 2015 19:09
Show Gist options
  • Save rpunt/5134907 to your computer and use it in GitHub Desktop.
Save rpunt/5134907 to your computer and use it in GitHub Desktop.
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