function Connect-EXOnline { $credentials = Get-Credential Write-Output "Getting the Exchange Online cmdlets" $Session = New-PSSession -ConnectionUri https://outlook.office365.com/powershell-liveid/ ` -ConfigurationName Microsoft.Exchange -Credential $credentials ` -Authentication Basic -AllowRedirection Import-PSSession $Session } function Show-Menu { param ( [string]$Title = "GCITS Distribution Group Editor" ) cls Write-Host "================ $Title ================" Write-Host "1: Press '1' to connect to Exchange Online. (Do this first)" Write-Host "2: Press '2' to add a single contact to a distribution group." Write-Host "3: Press '3' to get a list of distribution groups." Write-Host "4: Press '4' to create a distribution group." Write-Host "5: Press '5' to get a list of distribution group members." Write-Host "6: Press '6' to remove a contact." Write-Host "Q: Press 'Q' to quit." } function AddSingleToGroup { $name = Read-Host "Please enter the name of the external user" $email = Read-Host "Please enter the email of the external user" Write-Host "Current distribution Groups:" Get-DistributionGroup | ft Name, Identity $distributiongroup = Read-Host "Please enter the group name that you would like to add the user to" New-MailContact -Name $name -ExternalEmailAddress $email Add-DistributionGroupMember -Identity $distributiongroup -Member $email } function RemoveContact { $email = Read-Host "Please enter the email of the contact to remove" Write-Host "Removing Contact..." Remove-MailContact -identity $email } function CreateGroup { $groupName = Read-Host "Please enter the name of the distribution group" New-DistributionGroup -Name "$groupName" } function GetMembers { Write-Host "Current distribution Groups:" Get-DistributionGroup | ft Name, Identity $groupName = Read-Host "Please enter the name of the relevant distribution group" Get-DistributionGroupMember -Identity "$groupName" | ft Name, PrimarySMTPAddress } do { Show-Menu $input = Read-Host "Please make a selection" switch ($input) { '1' { cls Connect-EXOnline } '2' { cls AddSingleToGroup } '3' { cls Get-DistributionGroup | ft Name, Identity } '4' { cls CreateGroup } '5' { cls GetMembers } '6' { cls RemoveContact }'q' { return } } pause } until ($input -eq 'q')