啊直接上脚本吧。

在 Windows PowerShell 里运行以下命令:

Read-Host -Prompt "Please Enter the Password" -AsSecureString | ConvertFrom-SecureString | Out-File "C:\Temp\Cred.txt"

这会在 C 盘的 Temp 文件夹下面生成一个用于保存管理员邮箱登录凭证的文件。

然后把下面这段代码复制粘贴到记事本里面:

$userName = "管理员邮箱地址"
$password = Get-Content "C:\Temp\Cred.txt" | ConvertTo-SecureString
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList ($userName, $password)
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Authentication Basic -Credential $cred -AllowRedirection
Import-PSSession $Session
Get-Mailbox -ResultSize unlimited | where {$_.recipienttypedetails -eq "UserMailbox"} | Set-CasMailbox -OwaEnabled $false

然后把它保存成 .ps1 格式的文件。

最后参考这篇文档设置Windows  计划任务,定期执行上面的脚本。

比如,你通过计划任务把这个脚本设置成每周运行一次,那么每次它运行后,过去的这一周新增的 Exchange Online 用户的 OWA 邮箱都会被禁用。

非常好用。