This script was created to quickly configure a database mirroring failover partner on all databases in the farm. This script does not do any of the backend work to configure database mirroring and makes the following assumptions:

1. It assumes a one to one mirroring relationship. That is, it expects that all your databases reside on a single principal SQL instance and that you will be mirroring those databases to just one other SQL instance.

2. It assumes that you have rights to make these changes

3. It assumes that the mirror SQL instance is available. The script will fail if not.

4. It assumes that you have or will configure mirroring on the backend before a failover is required.

PowerShell
Edit|Remove
##################################################################
#
# Set the failover partner instance on every database in the farm
#
####### Instructions
#  Run this script in the SharePoint Management Shell
# When Prompted, enter the name of the SQL instance that will act
# as the mirror partner for each database
#
####### Known Issues
#  Script will fail if mirror SQL instance is offline or otherwise
# unavailable. 
#
##################################################################
Param([string]$FailoverInstance = $(Read-Host "Enter the Mirror (Partner) SQL Instance(like server\instance)"))
get-spserviceinstance -all | foreach-object {
	if ($_.typeName -eq "Microsoft SharePoint Foundation Database") {
		foreach ($Database in $_.Databases){
			
			write-host "Updating FailoverPartner on" $Database.Name "to" $FailoverInstance
			$Database.AddFailoverServiceInstance($FailoverInstance)
			$Database.Update()
			write-host "Successfully Updated Failover Partner on" $Database.Name "to" $FailoverInstance
		}
		
	}
}