Thursday 12 July 2018

Adding Users to O365 Distribution List

 

A script I recently used to add members to an office 365 distribution group using a remote exchange session in a hybrid setup (covered at the end). 

 

$SourceFile = "<path to file>"

Import-CSV $SourceFile | ForEach `

{Add-DistributionGroupMember -Identity "Group Name" -Member $_.UPN

Write-Host -ForegroundColor Green "Processed the record for $($_.UPN)"

}

 

 

CSV file contains UPNs of all users to be added.

 

I also found it useful to see who had permissions to send to this group using

 

 

(Get-DistributionGroup -Identity "Group Name").AcceptMessagesOnlyFrom | ForEach {Get-User -Identity $_}

 

 

To open remote exchange shell:

 

 

$UserCredential = Get-Credential

 

 

A prompt will appear for your login credentials then,

 

 

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection

Import-PSSession $Session

 

 

 

No comments:

Post a Comment