Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $Username = "o365-admin@tenant.onmicrosoft.com"
- $Password = Get-Content c:\o365_scripts\remoteps.pwd | ConvertTo-SecureString
- $Credential = New-Object System.Management.Automation.PSCredential($Username,$Password)
- $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://ps.outlook.com/powershell" -Credential $Credential -Authentication Basic -AllowRedirection
- $ImportResults = Import-PSSession $Session
- Import-Module MSOnline
- Connect-MSOLService -Credential $Credential
- $Mailboxes = Get-Mailbox -ResultSize Unlimited
- $PopGroup = Get-MSOLGroup -All | Where-Object {$_.DisplayName -eq "POP3-Users"}
- $ImapGroup = Get-MSOLGroup -All | Where-Object {$_.DisplayName -eq "IMAP-Users"}
- $EnablePOP = Get-MSOLGroupMember -GroupObjectId $PopGroup.ObjectId -All | Select-Object -ExpandProperty DisplayName
- $EnableImap = Get-MSOLGroupMember -GroupObjectId $ImapGroup.ObjectId -All | Select-Object -ExpandProperty DisplayName
- 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 }}
- Remove-PSSession -Session $Session
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement