By Using your below Script :
Import-Csv -Path "C:\temp\GroupsC.csv" | ForEach-Object {
$ownerUserObj = $UserObj = Get-AzureADUser -ObjectId $.GroupOwner
$newGroup = New-AzureADGroup -DisplayName $.GroupName -SecurityEnabled $true -MailEnabled $false -MailNickName "NotSet"
Add-AzureADGroupOwner -ObjectId $newGroup.ObjectId -RefObjectId $ownerUserObj.ObjectId
}
I am able to create the Groups and also can update Group Owner successfully But i am not sure why I get this Below Error :
Any Idea ???
Get-AzureADUser : Error occurred while executing GetUser
Code: Request_BadRequest
Message: The request URI is not valid. Since the segment 'Microsoft.DirectoryServices.User' refers to a collection, this must be the last segment in the request URI. All intermediate segments must refer
to a single resource.
RequestId: 1083e92b-026e-402c-b886-78377c359a0a
DateTimeStamp: Sun, 18 Sep 2022 15:32:32 GMT
HttpStatusCode: BadRequest
HttpStatusDescription: Bad Request
HttpResponseStatus: Completed
At line:2 char:28
- $ownerUserObj = $UserObj = Get-AzureADUser -ObjectId $.GroupOwner
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : NotSpecified: (:) [Get-AzureADUser], ApiException
- FullyQualifiedErrorId : Microsoft.Open.AzureAD16.Client.ApiException,Microsoft.Open.AzureAD16.PowerShell.GetUser
Get-AzureADUser : Error occurred while executing GetUser
Code: Request_BadRequest
Message: The request URI is not valid. Since the segment 'Microsoft.DirectoryServices.User' refers to a collection, this must be the last segment in the request URI. All intermediate segments must refer
to a single resource.
RequestId: e38b4fdf-a3f5-4dfa-b29e-0ce209beefd0
DateTimeStamp: Sun, 18 Sep 2022 15:32:32 GMT
HttpStatusCode: BadRequest
HttpStatusDescription: Bad Request
HttpResponseStatus: Completed
At line:2 char:28
- $ownerUserObj = $UserObj = Get-AzureADUser -ObjectId $.GroupOwner
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : NotSpecified: (:) [Get-AzureADUser], ApiException
- FullyQualifiedErrorId : Microsoft.Open.AzureAD16.Client.ApiException,Microsoft.Open.AzureAD16.PowerShell.GetUser