Azure Active Directory Powershell 管理

Azure Active Directory Powershell Management

代码:

$GroupObjectID = Get-AzureADGroup -SearchString "XXXXXXXXXXXXXXXXXXXX" | select ObjectId

Write-Output $GroupObjectID

Get-AzureADGroup -ObjectId $GroupObjectID

输出:

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
    

问题:write-output 语句返回一个 ObjectID,我将其存储并在下一行中查询与该 objectid 匹配的组。我假设我存储的是 system.object 而不是 system.String,但我该如何解决这个问题?

是否尝试使用以下 PowerShell 脚本并获得您正在寻找的预期输出

$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 

您的脚本无法运行的原因是因为脚本的第一行仅采用变量中的 objectID 并期望打印 DisplayName。由于 $GroupObjectID 变量具有三个不同的值,即 ObjectIDDisplayNameDescription,因此您必须传递所有要显示的参数。

$GroupObjectID = Get-AzureADGroup -SearchString "XXXXXXXXXXXXXXXXXXXX" | select ObjectId