首页 > 解决方案 > 绑定到 AD LDS 并更改用户密码

问题描述

我正在尝试以务实的方式(使用 powershell)绑定到 AD LDS(ADAM)目录并更改用户密码。

我尝试使用此 cmdlet

Set-ADAccountPassword -Identity $identity -Server 'localhost:389' -Reset -NewPassword (ConvertTo-SecureString -AsPlainText "$password" -Force);

如果我手动使用它可以正常工作,但如果由服务完成,即使服务以与手动运行时相同的用户身份运行,它也不起作用。如果有人有任何想法为什么会这样,我将不胜感激。

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;

        }

    }
}

标签: powershelladlds

解决方案


推荐阅读