Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Szeraax/bb0ba2c2569f5caaa9092ca791384d4d to your computer and use it in GitHub Desktop.
Save Szeraax/bb0ba2c2569f5caaa9092ca791384d4d to your computer and use it in GitHub Desktop.
# Usage:
# Edit default OU path if you aren't going to specify it on the command line (you normally won't).
# (If pasted into a script file, dot source it to bring functions into current scope)
# Connect to your EXO instance:
# & "C:\Program Files\Internet Explorer\iexplore.exe" https://cmdletpswmodule.blob.core.windows.net/exopsmodule/Microsoft.Online.CSE.PSModule.Client.application
# To list eligible groups:
# Get-AadMigrationEligibleDistributionGroups
# To Select some group\groups:
# Get-AadMigrationEligibleDistributionGroups | ogv -PassThru | Convert-AadMigrationEligibleDistributionGroups
# To migrate all groups:
# Get-AadMigrationEligibleDistributionGroups | Convert-AadMigrationEligibleDistributionGroups
function Get-AadMigrationEligibleDistributionGroups
{
[cmdletbinding()]
Param(
$Filter = "*"
)
$AADGroups = Get-DistributionGroup -Filter $Filter
$AADGroups | ? {!$_.IsDirSynced}
}
function Convert-AadMigrationEligibleDistributionGroups
{
[cmdletbinding()]
Param(
[Parameter(
Position=0,
ValueFromPipeline=$true)
]
[Alias('AzureADGroup')]
$AadGroup,
[switch]$WhatIf,
[string]$NewGroupPath = "OU=Users,DC=example,DC=com"
)
begin {
$ErrorActionPreference = "Stop"
}
process {
foreach($GroupToMigrate in $AadGroup)
{
$GroupMembers = Get-DistributionGroupMember $GroupToMigrate.Identity | select -Expand Name |
Foreach-Object {@(get-aduser -Filter "Name -eq '$_'")[0].SamAccountName}
New-ADGroup -Path $NewGroupPath -Name $GroupToMigrate.Name -GroupCategory Security -GroupScope Universal -WhatIf:$WhatIf -OtherAttributes @{
ProxyAddresses=($GroupToMigrate.EmailAddresses -join ";");
Mail=$GroupToMigrate.PrimarySmtpAddress;
msExchHideFromAddressLists=$GroupToMigrate.HiddenFromAddressListsEnabled;
msExchRequireAuthToSendTo=$GroupToMigrate.RequireSenderAuthenticationEnabled;
DisplayName=$GroupToMigrate.DisplayName;
}
Add-ADGroupMember -Identity $GroupToMigrate.Identity -Members $GroupMembers
}
}
end {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment