1

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.

0

You can use GetType() method

$web.GetType().Name 

If it is web it gives you SPWeb otherwise SPSite

Edit

$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 – user3426869 May 13 '15 at 14:01
  • $currentSite = Get-SPSite -Identity $siteFollowed.Uri.AbsoluteUri if($currentSite.CompatibilityLevel -eq 15){ } It can be nice if there is no error – user3426869 May 13 '15 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? – user3426869 May 13 '15 at 14:09
  • Yes but $currentSite is empty if object is not an SPSite, so GetType don't work :) – user3426869 May 13 '15 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 – Amal Hashim May 13 '15 at 14:14

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.