Reputation: 15
Code:
$GroupObjectID = Get-AzureADGroup -SearchString "XXXXXXXXXXXXXXXXXXXX" | select ObjectId
Write-Output $GroupObjectID
Get-AzureADGroup -ObjectId $GroupObjectID
Output:
ObjectId -------- a0xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx
Get-AzureADGroup : Error occurred while executing GetGroup Code: Request_BadRequest Message: Invalid object identifier '@{ObjectId=a0xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx}'. RequestId: xxxxxxxxxxxxxxxxxxx DateTimeStamp: Fri, 26 Nov 2021 14:56:43 GMT HttpStatusCode: BadRequest HttpStatusDescription: Bad Request HttpResponseStatus: Completed At line:1 char:1
- Get-AzureADGroup -ObjectId $DecryptGroupObjectID
+ CategoryInfo : NotSpecified: (:) [Get-AzureADGroup], ApiException + FullyQualifiedErrorId : Microsoft.Open.AzureAD16.Client.ApiException,Microsoft.Open.AzureAD16.PowerShell.GetGroup
Question: The write-output statement gives me an ObjectID back, I store this and in the next line query a group that matches this objectid. I assume I store a system.object instead of a system.String, but how can I solve this?
Upvotes: 0
Views: 1146
Reputation: 4602
Did try with below PowerShell Script and getting the expected output you are looking for
$GroupObjectID = Get-AzureADGroup -SearchString "'Merican Numero Uno"
Write-Output $GroupObjectID
Get-AzureADGroup -ObjectId $GroupObjectID.ObjectId
$GroupObjectID = Get-AzureADGroup -SearchString "'Merican Numero Uno" |select ObjectId,DisplayName,Description
Write-Output $GroupObjectID
Get-AzureADGroup -ObjectId $GroupObjectID.ObjectId
Reason for why your Script was not working because first line of script is only taking the objectID
in the variable and expecting to print the DisplayName
. As $GroupObjectID
variable has three different Value ie ObjectID
,DisplayName
,Description
so you have to pass the all the argument which you want to display.
$GroupObjectID = Get-AzureADGroup -SearchString "XXXXXXXXXXXXXXXXXXXX" | select ObjectId
Upvotes: 0