Created
January 22, 2019 16:12
-
-
Save zplume/a23cae4eaca2ef81e485a936370d7326 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param( | |
# Credentials paramter should be a variable containing the result of Get-Credential | |
[Parameter(Mandatory = $true)] | |
[pscredential]$Credentials, | |
[Parameter(Mandatory = $true)] | |
[string]$ConfigFile | |
) | |
$ErrorActionPreference = "Stop" | |
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $Credentials -Authentication Basic -AllowRedirection | |
Import-PSSession $Session -DisableNameChecking | Out-Null | |
try { | |
# Confirm connection to Exchange Online and cmdlets are available | |
$testCommand = Get-Command "Get-DistributionGroup" -EA "Stop" | |
Write-Host "`nCreating mail-enabled Azure AD security groups" | |
Write-Host "`nImporting $ConfigFile...`n" | |
Import-Csv -Path $ConfigFile | ForEach-Object { | |
try { | |
$group = Get-DistributionGroup -Identity $_.GroupName | |
Write-Host "Group '$($_.GroupName)' exists, skipping..." -ForegroundColor Yellow | |
} | |
catch { | |
Write-Host "Creating Mail-enabled security group '$($_.GroupName)'..." | |
New-DistributionGroup -Name $_.GroupName -Alias $_.MailNickName -Type "Security" | |
} | |
} | |
} | |
catch { | |
Write-Error "Unable to connect to Exchange Online" | |
} | |
Remove-PSSession $Session |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GroupName | MailNickName | |
---|---|---|
Mail-enabled Security Group | MailEnabledSecurityGroup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment