-
Notifications
You must be signed in to change notification settings - Fork 0
/
o365-set-legacy-protocol-all-mailbox-plans.ps1
80 lines (64 loc) · 3.19 KB
/
o365-set-legacy-protocol-all-mailbox-plans.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
$ErrorActionPreference = "Stop";
# Set IMAP, POP3, and ActiveSync for all mailboxes plans on a Office 365 tenant
# This will set any FUTURE accounts created under these mailboxes with the same settings
# Note you can't disable MAPI on mailbox plans. The documentation states "This parameter is reserved for internal Microsoft use."
# For accounts with MFA you need to install the Exchange Online Remote PowerShell Module
# https://docs.microsoft.com/en-us/powershell/exchange/exchange-online/connect-to-exchange-online-powershell/mfa-connect-to-exchange-online-powershell?view=exchange-ps
### Script config ###
# Multi-factor authentication
# Set to $true if you're using MFA for your administrator accounts (you should be)
$mfa=$true
# Set your administrator account below
$userPrincipalName="<admin>@<tenant>.onmicrosoft.com"
# Enable/Disable IMAP
$imapEnabled=$false
# Enable/Disable POP
$popEnabled=$false
# Enable/Disable ActiveSync
$activeSyncEnabled=$false
### End of script config ###
if ($mfa) {
Try {
#Connect to O365 Exchange with MFA
$Session = Connect-EXOPSSession -UserPrincipalName $userPrincipalName -ConnectionUri “https://ps.outlook.com/powershell"
}
Catch [System.Management.Automation.CommandNotFoundException] {
Write-Output "Please ensure you have the Exchange Online Remote PowerShell Module installed"
Write-Output "Visit https://docs.microsoft.com/en-us/powershell/exchange/exchange-online/connect-to-exchange-online-powershell/mfa-connect-to-exchange-online-powershell?view=exchange-ps"
Exit
}
Catch {
$ErrorMessage = $_.Exception.Message
$FailedItem = $_.Exception.ItemName
Write-Output "Failed to connect to O365 Exchange"
Write-Output "Error Message : $ErrorMessage"
throw $_
}
} else {
Try {
# Connect to O365 without MFA
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri “https://ps.outlook.com/powershell" -Credential $userPrincipalName -Authentication Basic -AllowRedirection
}
Catch [System.Management.Automation.CommandNotFoundException] {
Write-Output "Please ensure you have the MSOnline module installed"
Write-Ouptut "Run \"Install-Module MSOnline\" in elevated PowerShell"
Exit
}
Catch {
$ErrorMessage = $_.Exception.Message
$FailedItem = $_.Exception.ItemName
Write-Output "Failed to connect to O365 Exchange"
Write-Output "Error Message : $ErrorMessage"
throw $_
}
}
$mailboxPlans = Get-CASMailboxPlan -ResultSize Unlimited
Write-Output "Setting all $($mailboxPlans.Count) mailbox plans with the following settings:"
Write-Output $(if($imapEnabled) {"Enabling IMAP"} else {"Disabling IMAP"})
Write-Output $(if($popEnabled) {"Enabling POP"} else {"Disabling POP"})
Write-Output $(if($activeSyncEnabled) {"Enabling ActiveSync"} else {"Disabling ActiveSync"})
Read-Host -Prompt "Press any key to continue or CTRL+C to quit"
ForEach ($mailboxPlan in $mailboxPlans) {
Write-Output "Setting mailbox plan $($mailboxPlan.Identity))"
$mailboxPlan | Set-CASMailboxPlan -ImapEnabled $imapEnabled -PopEnabled $popEnabled -ActiveSyncEnabled $activeSyncEnabled
}