使用 PowerShell 管理密码
此文章适用于 Microsoft 365 企业版和 Office 365 企业版。
可以使用适用于 Microsoft 365 的 PowerShell 作为Microsoft 365 管理中心的替代方法,以管理 Microsoft 365 中的密码。
如果本文中的命令块要求指定变量值,请使用以下步骤。
- 将命令块复制到剪贴板,并将其粘贴到记事本或 PowerShell 集成脚本环境 (ISE) 。
- 填写变量值并删除“”<和“>”字符。
- 在 PowerShell 窗口或 PowerShell ISE 中运行命令。
使用用于图表模块的 Azure Active Directory PowerShell
首先, 连接到 Microsoft 365 租户。
设置密码
使用这些命令为用户帐户指定密码。
$userUPN="<user account sign in name, such as belindan@contoso.com>"
$newPassword="<new password>"
$secPassword = ConvertTo-SecureString $newPassword -AsPlainText -Force
Set-AzureADUserPassword -ObjectId $userUPN -Password $secPassword
强制用户更改其密码
使用以下命令设置密码并强制用户更改其新密码。
$userUPN="<user account sign in name, such as belindan@contoso.com>"
$newPassword="<new password>"
$secPassword = ConvertTo-SecureString $newPassword -AsPlainText -Force
Set-AzureADUserPassword -ObjectId $userUPN -Password $secPassword -EnforceChangePasswordPolicy $true
使用这些命令设置密码,并强制用户在下次登录时更改其新密码。
$userUPN="<user account sign in name, such as belindan@contoso.com>"
$newPassword="<new password>"
$secPassword = ConvertTo-SecureString $newPassword -AsPlainText -Force
Set-AzureADUserPassword -ObjectId $userUPN -Password $secPassword -ForceChangePasswordNextLogin $true
使用Microsoft Azure Active Directory模块进行Windows PowerShell
首先, 连接到 Microsoft 365 租户。
设置密码
使用这些命令为用户帐户指定密码。
$userUPN="<user account sign in name>"
$newPassword="<new password>"
Set-MsolUserPassword -UserPrincipalName $userUPN -NewPassword $newPassword
强制用户更改其密码
使用这些命令可强制用户更改其密码。
$userUPN="<user account sign in name>"
Set-MsolUserPassword -UserPrincipalName $userUPN -ForceChangePassword $true
另请参阅
使用 PowerShell 管理 Microsoft 365 用户帐户、许可证和组