Skip Ribbon Commands
Skip to main content

Quick Launch

Todd Klindt's home page > Todd Klindt's Office 365 Admin Blog > Posts > How to determine the SharePoint version in PowerShell
August 22
How to determine the SharePoint version in PowerShell

Now that SharePoint 2013 is out, you should all be writing PowerShell to take advantage of it. There have been some great improvements to PowerShell in SharePoint 2013. In other cases, the cmdlets you’ve come to know and love in SharePoint 2010 have new names in SharePoint 2013. What’s a PowerSheller to do? You could maintain different scripts for each environment. You could also have one script and when it starts ask the user which version of SharePoint is installed. Or, you could just have PowerShell ask itself. Smile You can determine which version of SharePoint is installed with this line:

(Get-PSSnapin microsoft.sharepoint.powershell).Version.Major

The Major version for SharePoint 2010 is 14, and 15 for SharePoint 2013. If you want to get all fancy, you could do something like this:

# Check which version of SharePoint is installed

# Add the snapin, in case it's not already installed
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$ver = (Get-PSSnapin microsoft.sharepoint.powershell).Version.Major
If ($ver -eq "15" )
        Write-Output "SharePoint 2013 is installed"
    elseif ($ver -eq "14")
        Write-Output "SharePoint 2010 is installed"
            Write-Output "Could not determine version of SharePoint"

This code will tell you which version you have. You can modify it for your own scripts.





Great post as usual

Todd have you ever come across away to tell when data in a site collection was changed?  We are taking over a large farm that has never had unused sites removed.   Any ideas? 
 on 9/6/2012 9:39 PM

Re: Great post as usual


You can get a list of site collectoins whose content has not changed in 30 days with this PowerShell:

Get-SPSite -Limit all | Where-Object { $_.LastContentModifiedDate -lt (get-date).adddays(-30) } | select url, LastContentModifiedDate

Change the -30 to however many days you want.

Todd O. KlindtNo presence information on 9/6/2012 10:02 PM

Re: How to determine the SharePoint version in PowerShell

I have tried using that column in the past and it seems that the crawl agent causes that column to be inaccurate.  This is for a WSS3.0 farm as well.  In the past I have tried to use the BWused column with some success, but still haven't found a bullet proof way to determine when a site collection was last accessed or updated.

 on 9/9/2012 11:15 AM

You can also use farm build version

 on 10/17/2012 9:13 AM

Re: You can also use farm build version

That _sort_ of works. It does work if the farm isn't configured yet. So if you're using PowerShell to build a farm, you can't use that method.

Todd O. KlindtNo presence information on 10/22/2012 2:26 AM

And SP2007

Hey Todd,
how would I detect SP2007 is installed?
I'm using
to allow me to run PS scripts against 2007, but it would be handy if I could detect that I need to do this, rather than just doing it blindly.

 on 10/25/2012 9:29 PM

Re: And SP2007

Personally I don't use PowerShell with SharePoint 2007 because it doesn't have cmdlets written by Microsoft. You can do a hell of a lot of damage to SharePoint with PowerShell without some of the checks in place that the proper cmdlets have. However, since I like you Craig, I'll tell you how anyway.

You can use this PowerShell against any version of SharePoint and it will give you the build number:

$farm = [microsoft.sharepoint.administration.spfarm]::local

You can pull out the Major property of the BuildVersion to get whether it's 12, 14, or 15.

Now be careful with that. I don't want you shooting your eye out.

Todd O. KlindtNo presence information on 10/26/2012 9:09 AM

SharePoint 2013 farm build version


Neeraj Sinha
 on 4/23/2014 11:16 AM

Re: SharePoint 2013 farm build version

Yup, that's been covered in multiple comments above.

Todd O. KlindtNo presence information on 4/25/2014 9:43 PM


this helped me to create a single powershell script file for our multiple versioned farm. Thanks Todd
 on 4/27/2015 3:22 AM

Add Comment

Items on this list require content approval. Your submission will not appear in public views until approved by someone with proper rights. More information on content approval.


Body *

Today's date *

Select a date from the calendar.
Please enter today's date so I know you are a real person


Want a message when I reply to your comment? Put your Twitter handle here.