Forum Discussion
How to disable IMAP/POP3 globally but excluding a specific mailbox?
- Jan 18, 2019
I called Microsoft today. There is the script to disable IMAP/POP for all mailboxes expect abc@abc.com.
Get-CASMailbox -ResultSize Unlimited | where {$_.Name -ne "abc"} | Set-CASMailbox -PopEnabled $false -ImapEnabled $false
Note: abc is the display name of mailbox abc@abc.com.
So disable all once
Enable the ones you want once
Then when you create the mailbox and run the Powershell script to disable that mailbox. Should take about 2 minutes to do, That avoids the manual work of logging into the control panel and disabling them manually!
Hope that clarifies and gives you the answer you need.
Best, Chris
Hi Chris,
This will do, but I prefer automation. I wonder if it is possible to excluding the specific mailbox in the disable all mailbox script.
Maybe I should post on PowerShell forum.
Thank you anyway!
Best,
- MrOCanadaJul 15, 2019Copper Contributor
fyi, Configuring the CAS Mailbox Plan will help with future mailbox creations.
https://gcits.com/knowledge-base/disable-pop-imap-mailboxes-office-365/
Disabling IMAP and POP for all future mailboxes
1Get-CASMailboxPlan -Filter {ImapEnabled -eq "true" -or PopEnabled -eq "true" } | set-CASMailboxPlan -ImapEnabled $false -PopEnabled $falseDisabling IMAP and POP for all existing mailboxes
1Get-CASMailbox -Filter {ImapEnabled -eq "true" -or PopEnabled -eq "true" } | Select-Object @{n = "Identity"; e = {$_.primarysmtpaddress}} | Set-CASMailbox -ImapEnabled $false -PopEnabled $false - Mario PastoraMar 29, 2019Brass Contributoris this also including Shared Mailboxes that are licensed?
- Grace YinJan 18, 2019Iron Contributor
I called Microsoft today. There is the script to disable IMAP/POP for all mailboxes expect abc@abc.com.
Get-CASMailbox -ResultSize Unlimited | where {$_.Name -ne "abc"} | Set-CASMailbox -PopEnabled $false -ImapEnabled $false
Note: abc is the display name of mailbox abc@abc.com.
- Grace YinJan 17, 2019Iron Contributor
Hi Vasil,
Thank you for your reply. Below is the scrip that I found online and tested and it works. It will disable IMAP/POP for all mailboxes. If I want to exclude mailbox abc@abc.com in this script, can you help me to modify the script?
$IMAPMBX = Get-CASMailbox -ResultSize Unlimited | ?{($_.ImapEnabled -eq $true) -or ($_.PopEnabled -eq $true)}
$IMAPCount = $IMAPMBX.count
If ($IMAPCount -gt "0") {
ForEach ($I in $IMAPMBX) {
$UPN = $I.PrimarySMTPAddress
$Alias = $Identity
"--------[IMAP/POP Disable]Start Processing IMAP/POP Disable for Mailbox $UPN--------" | Out-File -Filepath $Logpath2 -Append
try {
$error.Clear()
write-host "Disable IMAP/POP for mailbox $UPN" -ForegroundColor GREEN
"Disable IMAP/POP for mailbox $UPN" | Out-File -FilePath $LogPath2 -Append
Set-CASMailbox -Id $UPN -IMAPEnabled $false
Set-CASMailbox -Id $UPN -POPEnabled $false
}
Catch {
write-host "ERROR - Disabling IMAP/POP for $UPN" -ForeGroundColor RED
"ERROR - Disabling IMAP/POP for $UPN" | Out-File -FilePath $LogPath2 -Append
$error | Out-File -FilePath $LogPath2 -Append
}
}
}
Thanks in advance!
- VasilMichevJan 17, 2019MVP
It's almost certainly possible, as PowerShell is very flexible, however we cannot give you a specific answer without knowing all the details. One way would be to simply "hardcode" the addresses of these mailboxes as an exclusion in the script, so no matter how many times it runs it never toggles the setting on/off. You can also generalize this to using a CSV file which the script reads from.