It seems It is working now and thank so much for your help and for your prompt replies ..
How to Bulk Import CSV to create Security Groups and Add Groups Owner to those Groups Using Powershell in Azure AD
I am Looking for an Script where i can create 500 Security Groups by Bulk Import Power shell cmdlet and Add Group Owners in Azure AD at the same time .
Please help !!!
7 answers
Sort by: Most helpful
-
-
Andreas Baumgarten 120.4K Reputation points MVP
2022-09-17T10:26:52.317+00:00 Hi @Mourya, Aditya ,
maybe this helps to get started: https://morgantechspace.com/2021/12/create-security-group-and-add-members-in-azure-ad-using-powershell.html
Do you have a CSV file with the names of the new AD groups and the related AD user (owner)?
----------
(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)
Regards
Andreas Baumgarten -
Vinodh247 32,366 Reputation points MVP
2022-09-17T10:43:12.513+00:00 Hi Mourya,
Thanks for reaching out to Microsoft Q&A.
Please refer the below links, these has directions and steps.
EDIT
Please ignore the links above as it is related to Azure AD on-prem, I suggest you to refer the link posted by @Andreas Baumgarten
Please Upvote and Accept as answer if the reply was helpful.
-
Andreas Baumgarten 120.4K Reputation points MVP
2022-09-18T13:20:42.333+00:00 There is a minor mistake in the script. Sorry!
Please try this:
Import-Csv -Path "c:\temp\GroupsC.csv" | ForEach-Object { $ownerUserObj = Get-AzureADUser -ObjectId $_.GroupOwner $newGroup = New-AzureADGroup -DisplayName $_.GroupName -SecurityEnabled $true -MailEnabled $false -MailNickName "NotSet" Add-AzureADGroupOwner -ObjectId $newGroup.ObjectId -RefObjectId $ownerUserObj.ObjectId }
----------
(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)
Regards
Andreas Baumgarten -
Mourya, Aditya 21 Reputation points
2022-09-18T13:45:51.763+00:00 Still No Luck ,Got this Error ...
Get-AzureADUser : Cannot bind argument to parameter 'ObjectId' because it is an empty string.
At line:2 char:44- $ownerUserObj = Get-AzureADUser -ObjectId $_.GroupOwner
- ~~~~~~~~~~~~~
- CategoryInfo : InvalidData: (:) [Get-AzureADUser], ParameterBindingValidationException
- FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.Open.AzureAD16.PowerShell.GetUser
New-AzureADGroup : Cannot bind argument to parameter 'DisplayName' because it is an empty string.
At line:3 char:44- $newGroup = New-AzureADGroup -DisplayName $_.GroupName -SecurityEnab ...
- ~~~~~~~~~~~~
- CategoryInfo : InvalidData: (:) [New-AzureADGroup], ParameterBindingValidationException
- FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.Open.AzureAD16.PowerShell.NewGroup
Add-AzureADGroupOwner : Error occurred while executing AddGroupOwner
Code: Request_BadRequest
Message: One or more added object references already exist for the following modified properties: 'owners'.
RequestId: e2945e74-a689-4209-b8ea-2110bb370b37
DateTimeStamp: Sun, 18 Sep 2022 13:44:28 GMT
HttpStatusCode: BadRequest
HttpStatusDescription: Bad Request
HttpResponseStatus: Completed
At line:4 char:2- Add-AzureADGroupOwner -ObjectId $newGroup.ObjectId -RefObjectId $own ...
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : NotSpecified: (:) [Add-AzureADGroupOwner], ApiException
- FullyQualifiedErrorId : Microsoft.Open.AzureAD16.Client.ApiException,Microsoft.Open.AzureAD16.PowerShell.AddGroupOwner
Get-AzureADUser : Cannot bind argument to parameter 'ObjectId' because it is an empty string.
At line:2 char:44- $ownerUserObj = Get-AzureADUser -ObjectId $_.GroupOwner
- ~~~~~~~~~~~~~
- CategoryInfo : InvalidData: (:) [Get-AzureADUser], ParameterBindingValidationException
- FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.Open.AzureAD16.PowerShell.GetUser
New-AzureADGroup : Cannot bind argument to parameter 'DisplayName' because it is an empty string.
At line:3 char:44- $newGroup = New-AzureADGroup -DisplayName $_.GroupName -SecurityEnab ...
- ~~~~~~~~~~~~
- CategoryInfo : InvalidData: (:) [New-AzureADGroup], ParameterBindingValidationException
- FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.Open.AzureAD16.PowerShell.NewGroup
Add-AzureADGroupOwner : Error occurred while executing AddGroupOwner
Code: Request_BadRequest
Message: One or more added object references already exist for the following modified properties: 'owners'.
RequestId: 82b8d083-4ebd-44b5-b964-470111693e20
DateTimeStamp: Sun, 18 Sep 2022 13:44:28 GMT
HttpStatusCode: BadRequest
HttpStatusDescription: Bad Request
HttpResponseStatus: Completed
At line:4 char:2- Add-AzureADGroupOwner -ObjectId $newGroup.ObjectId -RefObjectId $own ...
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : NotSpecified: (:) [Add-AzureADGroupOwner], ApiException
- FullyQualifiedErrorId : Microsoft.Open.AzureAD16.Client.ApiException,Microsoft.Open.AzureAD16.PowerShell.AddGroupOwner