Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Get-PnPAzureADUser : Code: Request_UnsupportedQuery

I have this weird behavior inside my PnP Power Shell:-

now if i write this Power Shell i will get results:-

Get-PnPAzureADUser -Filter  {AccountEnabled eq true and Mail  eq 'test@test.com'}

but if i define the Mail inside a variable i will get this error:-

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

PS C:\windows\system32> $rrr = "test@test.com"
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

Or this

PS C:\windows\system32> $rrr = "'test@test.com'"
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

Any advice? how i can pass the Mail as a variable inside the Get-PnPAzureADUser??

>Solution :

Use a expandable string instead of a script block to formulate your filter:

$rrr = "test@test.com"
Get-PnPAzureADUser -Filter "AccountEnabled eq true and Mail eq '$rrr'"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading