I am trying to pragmatically (using powershell) bind to an AD LDS (ADAM) directory and change a users password.
I tried using this cmdlet
Set-ADAccountPassword -Identity $identity -Server 'localhost:389' -Reset -NewPassword (ConvertTo-SecureString -AsPlainText "$password" -Force);
which works fine if I use it manually, but it does not work if done by the service even though the service is running as the same user as when this is run manually. If anyone has any ideas why this would be I would appreciate it.
function JICSpwd {
Param(
[string]$username,
[string]$password
)
if ($username -and $password) {
if ($username -notmatch '^\d+$'){
$id_num = $(getID $username);
} else {
$id_num = $username;
}
try {
if ($id_num){
$identity = "CN=$id_num,OU=PortalUsers,CN=Portal,O=Jenzabar,C=US";
Set-ADAccountPassword -Identity $identity -Server 'my.domain.edu:389' -Reset -NewPassword (ConvertTo-SecureString -AsPlainText "$password" -Force);
Write-Log -Message "Successfully updated JICS password ($id_num)";
}
} catch [Exception] {
Write-Log -Message "Failed to update JICS password ($username)" -Level Warn;
Write-Log -Message "---> $_.Exception.GetType().FullName, $_.Exception.Message" -Level Warn;
}
}
}