| 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. 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" } else { 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. Enjoy, tk ShortURL: http://www.toddklindt.com/WhichSPVerPosh |