Bered

Create A new Office365 dynamic distribution list

Aug 20th, 2018
710
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ######################################
  2.  
  3. #Author = Bered
  4. #Created 21/08/2018
  5. #Name = Create Office365 Dynamic Distro Group
  6.  
  7. ######################################
  8.  
  9. #Connect To Office365 (Do not Change)
  10.     $UserCredential = Get-Credential
  11.     $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Authentication Basic -Credential $UserCredential
  12.     Import-PSSession $Session
  13.  
  14. #Variables
  15.         #New Group Name
  16.             $NewGroup = "Name of New Group"
  17.  
  18.         #New Group Alias (No Spaces)
  19.             $NewAlias = "Alias"
  20.  
  21.         #New Email Address
  22.             $NewEmail = "[email protected]"
  23.  
  24. #Create Dynamic Distribution Group
  25. New-DynamicDistributionGroup -Name $NewGroup -RecipientFilter {(RecipientType -eq 'UserMailbox') -and (CountryOrRegion -eq 'Australia') -and (-not(ResourceType -eq 'Room')) -and (-not(ResourceType -eq 'Equipment'))} -Alias $NewAlias -DisplayName $NewGroup -PrimarySmtpAddress $NewEmail
Advertisement
Add Comment
Please, Sign In to add comment