Forum Discussion

Kelsey_TC's avatar
Kelsey_TC
Copper Contributor
Dec 14, 2022

Adding AD account to distribution groups

Does anyone know of a script that will migrate security groups from Active Directory over to Distribution groups, we've had a look online and tried the scripts but it doesn't seem to work entirely

  • TurqayGencay's avatar
    TurqayGencay
    Copper Contributor

    Kelsey_TC 

     

    What scripts did you try? And what errors did it give? (If there were any errors at all)

     

    Can you try this for one group? :

     

     

    To migrate security groups from Azure AD to distribution groups using PowerShell, you can use the Convert-MsolGroupToDistributionGroupcmdlet. This cmdlet is part of the Azure Active Directory PowerShell for Graph module, so you will need to first install and connect to Azure AD using PowerShell.

    Here is an example of how you can use this cmdlet to migrate a security group to a distribution group:

     

    # Import the Azure AD PowerShell for Graph module
    Import-Module AzureAD

     

    # Connect to Azure AD
    Connect-AzureAD

     

    # Get the security group that you want to migrate
    $group = Get-AzureADGroup -SearchString "<SecurityGroupName>"

     

    # Convert the security group to a distribution group
    Convert-MsolGroupToDistributionGroup -ObjectId $group.ObjectId

     

    Please note that this is just an example and you may need to modify the script to fit your specific needs and environment. Also, keep in mind that this script will only work if you have the necessary permissions to manage Azure AD and distribution groups.

Resources