【问题标题】:A parameter cannot be found that matches parameter name 'PasswordPolicies' in Powershell在 Powershell 中找不到与参数名称“PasswordPolicies”匹配的参数
【发布时间】:2021-01-02 03:52:13
【问题描述】:

我试图将 Azure 用户的密码设置为永不过期。在此过程中,我尝试了以下命令

Get-AzADUser -ObjectId <valid Azure user> | Select-Object UserprincipalName,@{
>>     N="PasswordNeverExpires";E={$_.PasswordPolicies -contains "DisablePasswordExpiration"}
>> }

UserPrincipalName          PasswordNeverExpires
-----------------          --------------------
<valid Azure user>                        False

为了设置 PasswordNeverExpires 为 True,我执行了下面的命令

Set-AzADUser -ObjectId <valid Azure user> -PasswordPolicies DisablePasswordExpiration

但它会引发如下错误:

Update-AzADUser : A parameter cannot be found that matches parameter name 'PasswordPolicies'.
At line:1 char:51
+ ... ADUser -ObjectId <valid Azure user> -PasswordPolicies Disable ...
+                                                 ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Update-AzADUser], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.Azure.Commands.ActiveDirectory.UpdateAzureADUserCommand

有人可以帮我解决这个问题吗?

谢谢, 斯里拉姆。

【问题讨论】:

  • 查看Update-AzADUser 的文档。没有PasswordPolicies这样的开关,那么您是从哪里想到使用它的呢?
  • 我不熟悉 AD 或 AzADUsers,但似乎“PasswordPolicies”不是有效参数。你能检查一下它是一个参数还是一个方法?
  • 您在哪里找到PasswordPolicies 属性?
  • 您好,您有机会查看我的回答吗?有更新吗?

标签: azure powershell azure-active-directory


【解决方案1】:

Az Powershell 不提供设置密码策略功能。

请改用Azure AD Powershell

Set-AzureADUser -ObjectId <user ID> -PasswordPolicies DisablePasswordExpiration

如果您担心必须再次登录 Azure AD Powershell,可以connect a session using an existing token associated with the active azure context

例如:

# login
Connect-AzAccount -Tenant {your tenant}
# perform other Azure operations...

$currentAzureContext = Get-AzContext
$tenantId = $currentAzureContext.Tenant.Id
$accountId = $currentAzureContext.Account.Id
Connect-AzureAD -TenantId $tenantId -AccountId $accountId

然后你可以运行Set-AzureADUser cmd。

【讨论】:

  • 如果我的回答对您有帮助,您可以接受它作为答案(单击答案旁边的复选标记,将其从灰色切换为已填充。)。见meta.stackexchange.com/questions/5234/…。这对其他社区成员可能是有益的。谢谢。
猜你喜欢
  • 2021-10-15
  • 2019-04-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多