Forum Discussion
How to disable IMAP/POP3 globally but excluding a specific mailbox?
- Jan 17, 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.
Hi Chris,
Thank you very much! I didn't get it earlier. Yes, this is exact what I want.
Just want to confirm what the future mailbox means. Does it mean the new created mailbox after the first script running? Can I schedule the script to run daily so I don't have to manually run it every time after I create an account? Please advise!
Many thanks!
Well, there is a probably an easier way than that. So you do the following
1.) Disable all mailboxes with the Powershell script provided earlier
2.) Enable the ones you want with the Poweshell script provided earlier
For all new mailboxes
3.) Create new mailbox
4.) Disable IMAP and POP3 on that new mailbox here
https://support.microsoft.com/en-in/help/2416434/how-to-enable-or-disable-pop3-imap-mapi-outlook-web...
After you have done 1 and 2 you don't need to do them again. You just do actions 3 and 4 when you need to create a new mailbox.
Best, Chris
- 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 17, 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.
- Grace YinJan 16, 2019Iron Contributor
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,
- Jan 16, 2019Yes, it just a Powershell script to disable the IMAP/POP protocols on the mailbox.
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 - Grace YinJan 16, 2019Iron Contributor
Hi Chris,
Do we need to do step 4 manually every time when we create a new account?
Thanks,