使用PowerShell在Office365中重置密码

在Office 365pipe理员门户中重置密码时,我可以select在电子邮件中发送新密码,而不必先看到密码。

在这里输入图像说明

我知道我可以重置密码

Set-MsolUserPassword 

我是否也可以从Powershell中将密码电子邮件发送到我select的电子邮件地址 – 就像在UI中一样? 如果是的话,怎么样?

调整一下Mike111b的电子邮件地址:

你可以简单地使用:

 $Password = Set-MsolUserPassword -UserPrincipalName <UPN> 

然后使用Send-MailMessage命令。

Set-MsolUserPassword命令将密码作为输出返回,以便将其保存到variables中。

是啊。 检查Send-MailMessage cmdlet:

https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.utility/send-mailmessage

非常基本的实现:

 $UserPrincipalName = Read-Host "Enter the UserPrincipalName" $Password = Read-Host "Enter the new password" Set-MsolUserPassword -UserPrincipalName "$UserPrincipalName" -NewPassword "$Password" Send-MailMessage -To "$UserPrincipalName" -From "ENTER YOUR EMAIL HERE" -Subject "Password Reset" -Body "I have reset your password. Your new password is:`n`n$Password" 

针对发件人字段的身份validation默认情况下是针对当前用户进行身份validation的。 如果这不适合你,你可以使用-Credential参数。

我也build议随机化每个密码。 无论是从在线工具粘贴到PowerShell中,还是在PowerShell中执行都没关系,但是我会把它放在首位。