Skip to content

Cannot use KQL in Get-MgSite (PowerShell 7 only) #419

Closed

Description

@joshtransient

The following works on Windows PowerShell 5.1, but not PowerShell 7:

Get-MgSite -Search 'GroupId:76493310-6708-48a9-a4dc-d36e7a239ff1'

Error message returned in 7 is "Syntax error: character ':' is not valid at position 7 in 'GroupId:76493310-6708-48a9-a4dc-d36e7a239ff1'". Fiddler shows that PowerShell 7 URL-encodes the value in -Search:

/v1.0/sites?$search=GroupId%3A76493310-6708-48a9-a4dc-d36e7a239ff1

For whatever reason, the current 5.1 issue where an extra "?" appears with every query parameter call seems to do fine, as Fiddler captures this:

/v1.0/sites??$search=GroupId%3A76493310-6708-48a9-a4dc-d36e7a239ff1

Invoke-MgGraphRequest also forcefully adds a "$" to the search parameter with this example:

Invoke-MgGraphRequest -Uri '/v1.0/sites?search=GroupId:76493310-6708-48a9-a4dc-d36e7a239ff1'

...which causes it to fail with an HTTP 400 (again, only on 7)
AB#7399

Activity

  1. changed the title [-]Cannot use KQL in Get-MgSite[/-] [+]Cannot use KQL in Get-MgSite (PowerShell 7 only)[/+] on Oct 6, 2020
  2. ghost removed on Oct 8, 2020
  3. ATJSM commented on Oct 8, 2020

    @ATJSM

    I was experiencing a very similar issue with the Search switch in PowerShell 7.0.2.

    $searchString = "Weekly digest: Office 365 changes"
    $messages = Get-MgUserMessage -UserId $user -Search $searchString
    

    Error:
    $messages = Get-MgUserMessage -UserId $user -Search $searchString #`" …
    | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    | Syntax error: character ':' is not valid at position 13 in 'Weekly digest: Office 365 changes'.

    In order to fix it i had to use double quotes and escape them as follows:

    $searchString = "Weekly digest: Office 365 changes"
    $messages = Get-MgUserMessage -UserId $user -Search `"$searchString`"
    
  4. peombwa commented on Oct 21, 2020

    @peombwa
    Member

    This is indeed a client bug and is being tracked by #399. A workaround for now is to double quote your -Search value as mentioned by ATJSM .

  5. joshtransient commented on Nov 23, 2020

    @joshtransient
    Author

    This won't fly for the /sites endpoint with ?search. ?search always works with KQL and ?$search does not. This issue was opened for a SharePoint-specific reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions