SharePoint Farm Version Matched with Online XML

This script does what Microsoft could have done from the beginning. Provide an online XML file, with the different versions of SharePoint, so it is easier to match the build version number with the release name.

It will look at the farm version and match this with a publicly shared XML containing all SharePoint 2007, 2010 and 2013 releases. This XML will be updated as new updates are released.

Similar scripts will be produced for Exchange and Lync servers.

Note: This script has not been tested on SharePoint 2007 and earlier yet.

#-- Checks google.com for connection, writes status and proceeds with script if google.com is up
if(Test-Connection -computer google.com -count 1 -quiet) 
    {
    cls
    Write-Host -ForegroundColor Green “Connectivity confirmed, proceeding with script...`r`n”
    
    #-- Clears all variables used throughout this script
    $dottedVersion, $buildVersion, $tempFile, $xmldoc, $i = $null
    
    #-- Setting working directory as current directory
    [Environment]::CurrentDirectory = $PWD
    
    #-- Name of xml file to use
    $tempFile = "spversion.xml"

    #-- If temp file already exists, remove it
    if(Test-Path $tempFile){Remove-Item $tempFile}

    #-- Checking if SharePoint Portal Services (SPS) 2001 is installed, based on file presence and getting version number
    if(Test-Path "C:\Program Files\Common Files\Microsoft Shared\MSSearch\Bin\mssrch.dll"){$dottedVersion = (Get-Command "C:\Program Files\Common Files\Microsoft Shared\MSSearch\Bin\mssrch.dll").FileVersionInfo.ProductVersion}
    
    #-- Checking if SharePoint Portal Server (SPS) 2003 is installed, based on file presence and getting version number
    elseif(Test-Path "C:\Program Files\SharePoint Portal Server\Bin\mssrch.dll"){$dottedVersion = (Get-Command "C:\Program Files\SharePoint Portal Server\Bin\mssrch.dll").FileVersionInfo.ProductVersion}
    
    #-- Checking if Windows SharePoint Services (WSS) 2.0 is installed, based on add/remove programs entry and getting version number
    elseif(Get-ChildItem HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall | % {Get-ItemProperty $_.PsPath} | where {$_.Displayname -match "Windows SharePoint Services 2.0"}){$dottedVersion = (Get-ChildItem HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall | % {Get-ItemProperty $_.PsPath} | where {$_.Displayname -match "Windows SharePoint Services"} | select DisplayVersion).DisplayVersion}
    
    #-- Checking if SharePoint 2007 is installed, based on registry entry and getting version number
    elseif(Test-Path "HKLM:software\microsoft\shared tools\web server extensions\12.0"){$dottedVersion = (Get-item "HKLM:software\microsoft\shared tools\web server extensions\12.0").getvalue("version")}
    
    else{
        #-- Adds the PowerShell SharePoint snapin if it is not already added
        if((Get-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null){Write-Host -ForegroundColor Yellow "Adding Microsoft.SharePoint.PowerShell snap-in... " -NoNewline;Add-PSSnapin Microsoft.SharePoint.PowerShell; Write-Host -ForegroundColor Yellow "Done!"; $i = $True}
        
        #-- Gets farm version number objects for SP2010 or SP2013
        $buildVersion = (Get-SPFarm).Buildversion
        
        #-- Builds version string from objects aquired in the preceding line, by concatenating them seperated by a period 
        $dottedVersion = $buildVersion -join "."
        }

    #-- Removes leading zeros from $dottedversion (if any exists)
    $dottedVersion = $dottedVersion -replace '(?<=^|\.)0+(?=[^\.])',''
    
    #-- Downloads the public XML file
    Write-Host -ForegroundColor Yellow "Downloading xml file... " -NoNewline
    (New-Object System.Net.WebClient).DownloadFile("https://docs.google.com/uc?export=download&id=0B3OwYqqW3V0aRUhiUlRJSnJQMTA", $tempFile)  
    Write-Host -ForegroundColor Yellow "Done!`r`n"
    
    #-- Saves the content of the downloaded file as an xml array
    [xml]$xmldoc = Get-Content $tempFile

    #-- Finds the build version in the xml file and gives you the relevant entry
    if(($dottedVersion.Split(".")[0] -eq 10) -or ($dottedVersion.Split(".")[0] -eq 11)){$xmldoc.SPVersions.Legacy.Version | Where-Object {$_.Build -eq $dottedVersion}}
    elseif($dottedVersion.Split(".")[0] -eq 12){$xmldoc.SPVersions.SP2007.Version | Where-Object {$_.Build -eq $dottedVersion}}
    elseif($dottedVersion.Split(".")[0] -eq 14){$xmldoc.SPVersions.SP2010.Version | Where-Object {$_.Build -eq $dottedVersion}}
    elseif($dottedVersion.Split(".")[0] -eq 15){$xmldoc.SPVersions.SP2013.Version | Where-Object {$_.Build -eq $dottedVersion}}
    else{}

    #-- Removes the local xml
    Remove-Item $tempFile

    #-- Removes the PS snapin if added earlier in the script
    if($i){Remove-PSSnapin Microsoft.SharePoint.PowerShell}
    }

#-- Show message and stop script if google.com is down
else{Write-Host -ForegroundColor Red -NoNewline “Connection is down… Please try again when you have internet access."}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s