2

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

4

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"}

  • I'm having to use -Limit 1 as this portion of code is part of a greater loop that moves sites one-by-one. Using your above example is only getting me the host site (the one I wished to exclude), with the host name/port number etc. – George Grainger Mar 15 '16 at 10:48
  • I'm not sure I understand you. If sites are fetched one by one, why not use site url as -Identity on each loop? – Aziz Kabyshev Mar 15 '16 at 12:13
  • Because I'm not fetching the sites by identity, they're being served from the DB effectively randomly. However, there's one that needs to be excluded – George Grainger Mar 16 '16 at 9:07
  • Would you try without trailing / in URL? – Aziz Kabyshev Mar 16 '16 at 9:55
  • 1
    Reading over your edit, this is exactly what I was looking for! Thank you – George Grainger Mar 16 '16 at 10:17
-1

You can use | Where, for example:

Get-SPSite | where{$_.Url.Startswith("http://intranet....")}
  • Well, you are not using the -Filter parameter, which is what this question concerns – Robert Lindgren Jul 20 '18 at 11:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.