I have a simple question, how to determine with PowerShell if a SharePoint Site is a SPSite object or SPWeb?

I get all Site followed by user but some are SPSite.

1 Answer 1


You can use GetType() method


If it is web it gives you SPWeb otherwise SPSite


$currentSite = Get-SPSite -Identity $siteFollowed.Uri.AbsoluteUri if($currentSite.GetType().Name -eq "SPSite" ...
  • Thanks but to test "GetType()" you need to have an object. My problem is I want to know before instanciation if URL is SPSite or SPWeb, otherwise I had an error May 13, 2015 at 14:01
  • $currentSite = Get-SPSite -Identity $siteFollowed.Uri.AbsoluteUri if($currentSite.CompatibilityLevel -eq 15){ } It can be nice if there is no error May 13, 2015 at 14:03
  • Yes but it's the problem, this line call an error.... It's impossible to check before if I have to create SPWeb or SPSite? May 13, 2015 at 14:09
  • Yes but $currentSite is empty if object is not an SPSite, so GetType don't work :) May 13, 2015 at 14:13
  • Ok in that case you can add an AND clause which check if currentSite is null or not.. if not null then go ahead with your comparison May 13, 2015 at 14:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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