Online Training On SharePoint
                      

Tuesday, 4 November 2008

Getting SharePoint Server version with PowerShell Scripting

Recently I have written script with PowerShell to get the version of SharePoint. Here is the script with the detailed explanation:

cls
set-location HKLM:
$var= get-itemproperty -path "\Software\Microsoft\shared tools\web server extensions\12.0" -name Version
Write-Host "MOSS 2007 Version: " $var -foregroundcolor white -backgroundcolor blue
$Input = Read-Host "Please Press any key to continue"
set-location c:\

The set-location Cmdlet sets the working location to a specified location. That location could be a directory, a sub-directory, a registry location, or another location stack. So with the set-location HKLM we are setting the location to HKey_Local_Machine which is one node in registry.

Now we are declaring a variable with $var syntax. This variable will store the version of the SharePoint.

The Get-ItemProperty cmdlet gets the properties of the specified items. -path Specifies the path to the item and -name Specifies the name of the property or properties to retrieve. So here we are going to Hive Folder and getting the version. This value will be stored in var variable.

The Write-Host cmdlet creates a customized output window. We can specify the color of text in that windows by using the ForegroundColor parameter and we can specify the background color of the window by using the Background Color parameter.So here we are appending "MOSS 2007 Version:" with the value retrived of SahrePoint version with variable var.

The Read-Host cmdlet reads a line of input from the console. We can use it to prompt a user for input. So here this command displays the string "Please Press any key to continue:" as a prompt. When a value is entered and the Enter key is pressed, the value is stored in the $Input variable. With that we are setting the location to C:\.

You can also find interesting to read: Getting All the Web Objects URL in a SharePoint farm using PowerShell Scripting


kick it on DotNetKicks.com

Post a Comment
Related Posts with Thumbnails