Friday 7 March 2014



As part of the summary script I use the following code to get the SharePoint 2010 build version. This identifies which CU or Service Pack has been installed.
There are a couple of ways for getting the build version:
1. Using Central Administration
It is of course possible to get the build version using central administration by going to ‘Central Administration –> System Settings –> Manage servers in this farm’


image



2. Using get-spfarm
You can use the following line of code to get the buildversion

get-spfarm | select BuildVersion
image
3. Using [Microsoft.SharePoint.Administration.SPFarm]::Local
This command outputs the same values as get-spfarm.
([Microsoft.SharePoint.Administration.SPFarm]::Local).buildversion
image
Use .tostring() to get the version as string.
image
 Cleaning up deleted databases in SharePoint

A service application database was deleted in SQL Server Management Studio. After a while, I noticed errors in the event viewer on the WFE and ULS logs complaining that SharePoint was not able to login to the database that I deleted. Obviously, SharePoint still thought that the database existed so I needed to find a way to remove it.

PowerShell to the rescue.
Solution

Using PowerShell, run the following command:

                 Get-SPDatabase | where {$_.exists -eq $false}


This will list all databases in SharePoint that no longer exist on the database server. If you are happy with the result and wish to remove the orphaned databases, run the following command:

                Get-SPDatabase | where {$_.exists -eq $false} | foreach {$_.delete()}


All orphaned databases should now be removed and SharePoint should stop complaining about being unable to login to the non-existent database.

Thursday 6 March 2014


Site collection Backup/Restore SharePoint Management Shell commands


There are a lot of ways to take backup of a Site collection/Web application but frequently used method is using SharePoint Management Shell.

1) Backup Command:

         Backup-SPSite -Identity http://ABC:2020 -Path C:/Mybackups/Mywebapp.bak -Force

Where http://ABC:2020 is the URLof the desired web application/site collection for taking backup and C:/Mybackups/Mywebapp.bak is the path to the physical drive where want to keep the backup.

2) Restore Command:

         Restore-SPSite -Identity http://XYZ:3030 -Path C:/Mybackups/Mywebapp.bak -Force

Now http://XYZ:3030 is the URL of desired web application/site collection and C:/Mybackups/Mywebapp.bak 
is the location of backup.