1

I want to do a simple task, I made a script who get all followed site from a user. But I want to filter it with compatibilitylevel.

With few sites, it's Ok, I do :

$currentSite = Get-SPSite -Identity $siteFollowed.Uri.AbsoluteUri
if($currentSite.CompatibilityLevel -eq 15){
   #...
}

But with many sites, it's not Ok because I get SPWeb too... So I have this error :

Get-SPSite : Cannot find an SPSite object with Id or Url: 

When I replace Get-SPSite by Get-SPWeb, I can get this site but I can't get compatibilitylevel....

Object SPSite :
Url                                                     CompatibilityLevel  
---                                                     ------------------  
https://site.fr/sites/test               15                  

Object SPWeb :
Url                                                    
---                                                    
https://site.domain.fr/sites/Collec_SRO/en...

=> No compatibilityLevel...

Do you have an idea to get the sharepoint version? (2010/2013, 14/15)

Thanks.

2

Try this:

$currentSite = Get-SPSite -Identity $siteFollowed.Uri.AbsoluteUri

  foreach($web in $currentSite.AllWebs){
   $web.Url version is $web.UIVersion #4 or 15
  }
}
  • Last question, how to determine with powershell if a Sharepoint site is a SPSite object or SPWeb? – user3426869 May 13 '15 at 13:52
  • if you use Get-SPWeb <URL> successfully, then it is an SPWeb. However all site collections will have a rootweb. – Mike May 13 '15 at 13:54
  • Thanks but if you do this, you had an error, you can't test URL without instanciation? – user3426869 May 13 '15 at 14:02
  • Check this: sharepoint.stackexchange.com/questions/4636/… – Mike May 13 '15 at 14:16
0

You can use GetType() method

$web.GetType().Name 

If it is web it gives you SPWeb otherwise 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:00

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.