使用powershell重置邮箱密码时找不到密码参数

时间:2011-07-28 21:33:42

标签: c# powershell

我正在使用powershell命令重置现有邮箱的密码,但是,它出现一条错误消息“无法找到与参数名称'密码'匹配的参数。”这很奇怪,因为'密码'是根据MSDN http://technet.microsoft.com/en-us/library/bb123981.aspx的参数。我错过了什么? 我的代码:

using (Runspace remoteRunspace = RunspaceFactory.CreateRunspace(connectionInfo))
    {
        try
        {
            remoteRunspace.Open();

            PowerShell ps = PowerShell.Create();
            ps.Runspace = remoteRunspace;
            ps.AddCommand("Set-Mailbox");
            string PrincipalName = userId + emailDomain;
            ps.AddParameter("Identity", identity);
            ps.AddParameter("UserPrincipalName", PrincipalName);
            ps.AddParameter("Name", name);
            ps.AddParameter("DisplayName", name);
            ps.AddParameter("Password", emailPwd);//emailPwd is defined as securestring and set value previously, so it cannot be the exception reason
            ps.Invoke();
            return true;
        }
        catch (Exception ex)
        {
            throw ex;
            return false;
        }
        finally
        {
            remoteRunspace.Close();
        }

2 个答案:

答案 0 :(得分:1)

来自文档:

此参数适用于基于云的服务中的对象。它不适用于内部部署。

此参数可用于多租户部署。它不适用于内部部署。有关多租户部署的详细信息,请参阅多租户支持。

Password参数重置与基于云的邮箱关联的用户帐户的密码。

答案 1 :(得分:0)

如果您使用的是内部部署Exchange,则设置密码是AD帐户管理功能。根据您的域级别,您可以使用ADSI,RSAT工具中的AD模块或Quest AD cmdlet。