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.

user3426869
  • 173
  • 2
  • 5
  • 15

2 Answers2

2

Try this:

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

  foreach($web in $currentSite.AllWebs){
   $web.Url version is $web.UIVersion #4 or 15
  }
}
Mike
  • 12,186
  • 8
  • 41
  • 64
  • 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 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: http://sharepoint.stackexchange.com/questions/4636/powershell-and-checking-for-site-existence – 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

Amal Hashim
  • 28,306
  • 5
  • 31
  • 61
  • 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