SOLVED

Powershell script that add newly created group to an administrative unit

Brass Contributor

I have this script.

 

# Import the AzureAD PowerShell module
Import-Module AzureAD

# Connect to Azure AD
Connect-AzureAD

# Define the path to the CSV file
$filePath = "groupimport1.csv"

# Define the administrative unit ID
$auId = "d752e951-77d9-4d26-b9d5-2d0f0464b8e2"

# Read the CSV file and create the groups
$groups = Import-Csv $filePath


foreach($group in $groups) {
$newGroup = New-AzureADMSGroup -DisplayName $group.Name -MailNickname $group.MailNickname -SecurityEnabled $true -MailEnabled $false -GroupTypes "DynamicMembership" -MembershipRule 'user.userPrincipalName -startsWith "group"' -MembershipRuleProcessingState "On"
$groupId = $newGroup.Id
#Do something with the groupId here
	
}

 

It works. It creates a new group from my csv file.

 

But now i want to add each group to a specific administrative unit. But i cant find how i do this.

I prepered with the auID to use in combination with newGroup.Id

 

Anyone able to tell me what to include in the foreach?

 

1 Reply
best response confirmed by oskarkuus (Brass Contributor)
Solution

Hello @oskarkuus,

You need to use Add-AzureADAdministrativeUnitMember

from AzureADPreview module.

In order to complete your script you would include something similar into your foreach:

Add-AzureADAdministrativeUnitMember -ObjectId $auID -RefObjectId $groupId

 

Hope that helps.

 

 

1 best response

Accepted Solutions
best response confirmed by oskarkuus (Brass Contributor)
Solution

Hello @oskarkuus,

You need to use Add-AzureADAdministrativeUnitMember

from AzureADPreview module.

In order to complete your script you would include something similar into your foreach:

Add-AzureADAdministrativeUnitMember -ObjectId $auID -RefObjectId $groupId

 

Hope that helps.

 

 

View solution in original post