Using Get-SPSite -Filter
-
08-10-2020 - |
Question
I seem to be having some trouble using the Filter
parameter on the Get-SPSite
cmdlet.
Using this question for reference, I'd hoped to filter out the Site that I was getting, to later on exclude it from being moved outside the Content DB.
I'm getting an error on the line;
Get-SPSite -Filter {$_.Url -ne "http://mysites.dev.local/"} -ContentDatabase "WSS_Content_MySites" -Limit 1
The error being:
Get-SPSite : Not a valid filter string format. The format is (property) (operator) (value).
I don't seem to be doing anything differently from the aforementioned question. Could anyone help?
Answer Edit:
From this blog, I found this little gem:
The filter parameter support is as follows:
a. SPWeb supports: Title and Template
b. SPSite and SPSiteAdministration supports: Owner, SecondaryContact, and LockState
It seems the -Filter
parameter is very limited in what it can provide, and thus in this instance, was necessary to use a Where-Object
La solution
Check Get-SPSite documentation:
The Filter parameter is a server-side filter for certain site collection properties that are stored in the content database; without the Filter parameter, filtering on these properties is a slow process. These site collection properties are Owner, SecondaryOwner, and LockState. The Filter parameter is a script block that uses the same syntax as a Where-Object statement, but is run on the server for faster results.
I think it's stated we can't filter by anything except Owner, SecondaryOwner, LockState
in Get-SPSite -filter
. Matches my experiments. Let's see documentation on Get-SPWeb:
The Filter parameter is a server-side filter for certain subsite properties that are stored in the content database; without the Filter parameter, filtering on these properties is a slow process. These subsite properties are Template and Title. The Filter parameter is a script block that uses the same syntax as a Where-Object statement, but is run server-side for faster results.
I read it like this: we can't filter by anything except Template, Title
in Get-SPWeb -filter
.
So
Get-SPSite -Filter {$_.Url -ne "http://mysites.dev.local"}
will not work and should be replace with semantically equivalent
Get-SPSite | ? {$_.Url -ne "http://mysites.dev.local"}
Autres conseils
You can use | Where, for example:
Get-SPSite | where{$_.Url.Startswith("http://intranet....")}