Advertisement
Guest User

Untitled

a guest
Jan 18th, 2016
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $Username = "o365-admin@tenant.onmicrosoft.com"
  2. $Password = Get-Content c:\o365_scripts\remoteps.pwd | ConvertTo-SecureString
  3. $Credential = New-Object System.Management.Automation.PSCredential($Username,$Password)
  4. $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://ps.outlook.com/powershell" -Credential $Credential -Authentication Basic -AllowRedirection
  5. $ImportResults = Import-PSSession $Session
  6. Import-Module MSOnline
  7. Connect-MSOLService -Credential $Credential
  8.  
  9. $Mailboxes = Get-Mailbox -ResultSize Unlimited
  10. $PopGroup = Get-MSOLGroup -All | Where-Object {$_.DisplayName -eq "POP3-Users"}
  11. $ImapGroup = Get-MSOLGroup -All | Where-Object {$_.DisplayName -eq "IMAP-Users"}
  12. $EnablePOP = Get-MSOLGroupMember -GroupObjectId $PopGroup.ObjectId -All | Select-Object -ExpandProperty DisplayName
  13. $EnableImap = Get-MSOLGroupMember -GroupObjectId $ImapGroup.ObjectId -All | Select-Object -ExpandProperty DisplayName
  14.  
  15. ForEach ($Mailbox in $Mailboxes) {
  16.   If ($EnablePop -Contains $Mailbox) {
  17.     $Mailbox | Set-CASMailbox -PopEnabled $True }
  18.   Else {
  19.     $Mailbox | Set-CASMailbox -PopEnabled $False }
  20.   If ($EnableImap -Contains $Mailbox) {
  21.     $Mailbox | Set-CASMailbox -ImapEnabled $True }
  22.   Else {
  23.     $Mailbox | Set-CASMailbox -ImapEnabled $False }}
  24.  
  25. Remove-PSSession -Session $Session
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement