代码之家  ›  专栏  ›  技术社区  ›  john Gu

获取PnPAzureADU用户:代码:Request_UnsupportedQuery

  •  1
  • john Gu  · 技术社区  · 3 年前

    我的PnP Power Shell中有这种奇怪的行为:-

    现在,如果我写下这个PowerShell,我会得到结果:-

    Get-PnPAzureADUser -Filter  {AccountEnabled eq true and Mail  eq '[email protected]'}
    

    但如果我在一个变量中定义Mail,我会得到以下错误:-

    PS C:\windows\system32> $rrr = "[email protected]"
    PS C:\windows\system32> Get-PnPAzureADUser -Filter  {AccountEnabled eq true and Mail  eq $rrr}                          
    Get-PnPAzureADUser : Code: Request_UnsupportedQuery
    Message: Unsupported Query.
    Inner error:
            AdditionalData:
            date: 2022-12-28T22:13:33
            request-id: 3f8d45ef-ab8e-49c9-bf6e-41e4a56c11e3
            client-request-id: 3f8d45ef-ab8e-49c9-bf6e-41e4a56c11e3
    ClientRequestId: 3f8d45ef-ab8e-49c9-bf6e-41e4a56c11e3
    At line:1 char:1
    + Get-PnPAzureADUser -Filter  {AccountEnabled eq true and Mail  eq $rrr ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [Get-PnPAzureADUser], PSInvalidOperationException
        + FullyQualifiedErrorId : InvalidOperation,PnP.PowerShell.Commands.Principals.GetAzureADUser
    

    或者这个

    PS C:\windows\system32> $rrr = "'[email protected]'"
    PS C:\windows\system32> Get-PnPAzureADUser -Filter  {AccountEnabled eq true and Mail  eq $rrr}                          
    Get-PnPAzureADUser : Code: Request_UnsupportedQuery
    Message: Unsupported Query.
    Inner error:
            AdditionalData:
            date: 2022-12-28T22:13:33
            request-id: 3f8d45ef-ab8e-49c9-bf6e-41e4a56c11e3
            client-request-id: 3f8d45ef-ab8e-49c9-bf6e-41e4a56c11e3
    ClientRequestId: 3f8d45ef-ab8e-49c9-bf6e-41e4a56c11e3
    At line:1 char:1
    + Get-PnPAzureADUser -Filter  {AccountEnabled eq true and Mail  eq $rrr ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [Get-PnPAzureADUser], PSInvalidOperationException
        + FullyQualifiedErrorId : InvalidOperation,PnP.PowerShell.Commands.Principals.GetAzureADUser
    

    有什么建议吗?如何将邮件作为变量传递到 Get-PnPAzureADUser ??

    1 回复  |  直到 3 年前
        1
  •  1
  •   Santiago Squarzon    3 年前

    使用 expandable string 而不是 script block 制定过滤器:

    $rrr = "[email protected]"
    Get-PnPAzureADUser -Filter "AccountEnabled eq true and Mail eq '$rrr'"
    
    推荐文章