Skip to content

Instantly share code, notes, and snippets.

@huzzeytech
Created October 18, 2018 15:01
Show Gist options
  • Save huzzeytech/9646bba9fbaf8298f6bfacae06edae53 to your computer and use it in GitHub Desktop.
Save huzzeytech/9646bba9fbaf8298f6bfacae06edae53 to your computer and use it in GitHub Desktop.
$username = $args[0]
$hostname = $args[1]
$currentPassword = $args[2]
$newPassword = $args[3]
Add-Type -AssemblyName System.DirectoryServices.AccountManagement
$principalContext = New-Object System.DirectoryServices.AccountManagement.PrincipalContext("Machine", $hostName)
try
{
$User = [System.DirectoryServices.AccountManagement.UserPrincipal]::FindByIdentity($principalContext, "SamAccountName", $username)
$User.ChangePassword($currentPassword, $newPassword)
}
catch
{
throw $_.Excepion.InnerException
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment