pnp / PnP-PowerShell

SharePoint PnP PowerShell CmdLets
https://pnp.github.io/powershell
Other
988 stars 663 forks source link

Get-PnPTenantSite -Filter property Expression Language syntax interpret filter component as joinoperator #1869

Open AndersRask opened 5 years ago

AndersRask commented 5 years ago

Reporting an Issue or Missing Feature

Issue when calling Get-PnPTenantSite -Filter "Url -like 'leg-legacy368'"

Expected behavior

All sites matching the filter

Actual behavior

Get-PnPTenantSite : Syntax error in the filter expression 'Url -like 'leg-legacy368''.
At line:331 char:33
+ ... stingSite = Get-PnPTenantSite -Filter "Url -like '$alias'" -Connectio ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (:) [Get-PnPTenantSite], ServerException
    + FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.GetTenantSite

The problem is the '-le' in the filter component 'leg-legacy368' is interpreted as a join operator (-le) The same problem can be observed for -eq, -ne, -like, -notlike:

Get-PnPTenantSite : Syntax error in the filter expression 'Url -like 'test-equal368''.
At line:1 char:1
+ Get-PnPTenantSite -Filter "Url -like 'test-equal368'"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (:) [Get-PnPTenantSite], ServerException
    + FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.GetTenantSite

Steps to reproduce behavior

Type any of the following commands

Get-PnPTenantSite -Filter "Url -like 'leg-legacy368'"
Get-PnPTenantSite -Filter "Url -like 'leg-liketest368'"
Get-PnPTenantSite -Filter "Url -like 'test-net368'"
Get-PnPTenantSite -Filter "Url -like 'test-like368'"
Get-PnPTenantSite -Filter "Url -like 'test-notlike368'"
Get-PnPTenantSite -Filter "Url -like 'test-equal368'"

Which version of the PnP-PowerShell Cmdlets are you using?

What is the version of the Cmdlet module you are running?

3.5.1901.0 SharePointPnPPowerShellOnline

How did you install the PnP-PowerShell Cmdlets?

erwinvanhunen commented 5 years ago

Hi!

Thank for your reporting this. Unfortuately I cannot fix this, as this is out of the scope of PnP PowerShell. The Get-PnPTenantSite cmdlet is the PnP equivalent of the Get-SPOSite cmdlet in the Office 365 Management Shell and we have feature parity with that cmdlet. We use both the same backend code to execute the request, and also Get-SPOSite has an issue with that specific filter. The filter is added to a request and then sent off to the server, which executes the request with the filter. In this case it's the server not being able to parse the filter.

We're investigating what's happening server side with this filter but not guarantees (as we have no control over the server side code) if this will be fixed.

As temporary work around, consider modifying your filter to

Get-PnPTenantSite -Filter "Url -like 'leg*legacy368'"
AndersRask commented 5 years ago

The workaround will require string replacement, as it is generated on-the-fly. Can you confirm if multiple wildcards are allowed? (eg replace all instances of '-' with '*'

AndersRask commented 5 years ago

@erwinvanhunen unfortunately wildcards cannot be used the way you mention.

From my tests I find that wildcards only works as a pre- or suffix, not in the middle of the string: Also, as soon as you start adding wildcards, you must either add complete url or always prefix with *, as only filter on Url (not alias/title) seems to be supported! get-pnptenantsite : Filtering is not supported for property Title.

No hits

Get-PnPTenantSite -Filter "Url -like 'leg*legacy368'"

No hits

Get-PnPTenantSite -Filter "Url -like 'leglegacy368'"

No hits

Get-PnPTenantSite -Filter "Url -like 'leglegacy368*'"

Only way I found to match was to drop the prefix name completely:

Get-PnPTenantSite -Filter "Url -like '*legacy368'"

So far this works for me, as the naming is unique, but for less strict naming conventions this would not be optimal