[英]Using Powershell with large O365 Tenants
I have been tasked with creating a powershell script that will crawl through one of our clients Office365 enviroments daily and disable POP/IMAP Access to anyone not in a specific security group. 我的任务是创建一个Powershell脚本,该脚本每天都会在我们的一个客户端Office365环境中进行爬网,并对不属于特定安全组的任何人禁用POP / IMAP访问。
I have written the code and it works, up until it gets about 75% of the way through our ~5000+ mailboxes, then it starts to fail with "Starting a command on the remote server failed with the following error message : The I/O operation has been aborted because of either a thread exit or an application request. For more" 我已经编写了代码,并且可以正常工作,直到通过我们的〜5000 +邮箱获得大约75%的方式为止,然后它开始失败,并显示为“在远程服务器上启动命令失败,并显示以下错误消息:I /由于线程退出或应用程序请求,O操作已中止。更多信息”
I imagine it is somehow timing out due to there being so many mailboxes, but not sure how to more efficiently write my script? 我想这是由于存在这么多邮箱而以某种方式超时了,但不确定如何更有效地编写我的脚本吗? Any ideas?
有任何想法吗?
Connect-EXOPSSession
Connect-MSOLService
$PopGroup = Get-MSOLGroup -All | Where-Object {$_.DisplayName -eq "POP Exception"}
$ImapGroup = Get-MSOLGroup -All | Where-Object {$_.DisplayName -eq "IMAP Exception"}
$EnablePOP = Get-MSOLGroupMember -GroupObjectId $PopGroup.ObjectId -All | Select-Object -ExpandProperty DisplayName
$EnableImap = Get-MSOLGroupMember -GroupObjectId $ImapGroup.ObjectId -All | Select-Object -ExpandProperty DisplayName
$Mailboxes = $Mailboxes = Get-Mailbox -ResultSize Unlimited
ForEach ($Mailbox in $Mailboxes) {
If ($EnablePop -Contains $Mailbox) {
$Mailbox | Set-CASMailbox -PopEnabled $True }
Else {
$Mailbox | Set-CASMailbox -PopEnabled $False }
If ($EnableImap -Contains $Mailbox) {
$Mailbox | Set-CASMailbox -ImapEnabled $True }
Else {
$Mailbox | Set-CASMailbox -ImapEnabled $False }}
That error message appears to be a performance limitation or I/O timeout (see this blog entry from MS for example of this issue). 该错误消息似乎是性能限制或I / O超时(有关此问题的示例,请参阅MS的此博客条目 )。 I have a couple of ideas to try:
我有几个想法可以尝试:
$PopGroup = Get-MSOLGroup -SearchString "POP Exception"
$PopGroup = Get-MSOLGroup -SearchString "POP Exception"
Try using Get-CASMailbox instead of getting all mailboxes with all of their data: 尝试使用Get-CASMailbox而不是使用其所有数据获取所有邮箱:
Get-CASMailbox -ResultSize Unlimited | foreach-object { $upn = "$_@YOURDOMAIN.COM" if($_.POPEnabled -eq $true -and $(!($EnablePop.EmailAddress -Contains $upn))){ Set-CASMailbox -Identity $upn -PopEnabled $false } elseif ($_.POPEnabled -eq $false -and $EnablePop -Contains $upn){ Set-CASMailbox -Identity $upn -PopEnabled $true } if($_.ImapEnabled -eq $true -and $(!($EnableImap -Contains $upn))){ Set-CASMailbox -Identity $upn -ImapEnabled $false } elseif($_.ImapEnabled -eq $false -and $EnablePop -Contains $upn){ Set-CASMailbox -Identity $upn -ImapEnabled $true } }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.