The purpose of the Get-SPBackupHistory cmdlet is pretty self-explanatory. It outputs a listing of the Backup-SPFarm and Restore-SPFarm operations that have been conducted using the files in the specified directory. The Get-SPBackupHistory cmdlet uses the spbrtoc.xml file stored within the target backup storage directory to determine and display information.
Caution
The Get-SPBackupHistory cmdlet can only be used to display information on backups created via the Backup-SPFarm cmdlet, restores conducted via the Restore-SPFarm
cmdlet, or catastrophic operations run using the Central Administration
site’s backup or restore tools. It does not work for other types of
backups, such as site collection backups via Backup-SPSite.
A sample Get-SPBackupHistory request is listed next:
Get-SPBackupHistory -Directory \\backups
You can use the following switches and input parameters with the Get-SPBackupHistory operation:
Directory. This input parameter is required when running Get-SPBackupHistory. The same rules apply to this parameter as the Directory input parameters for the restore and backup cmdlets discussed earlier.
AssignmentCollection.
This is an optional parameter, intended to allow for the proper
disposal of objects. Consider using this parameter if your call of Get-SPBackupHistory also involves using SharePoint’s SPWeb, SPSite, or SPSiteAdministration objects; otherwise, it is not likely to be necessary.
ShowBackup. This input switch is not required when running Get-SPBackupHistory. When used, it filters the output of the operation so that the cmdlet returns only backup operation history data.
ShowRestore. This input switch is not required when running Get-SPBackupHistory. When used, it filters the output of the operation so that the cmdlet displays only restore operation history data.
Note
If you omit the Backup and Restore switches from the Get-SPBackupHistory request, the cmdlet returns the history data for all backup and restore operations. If you use the Backup and Restore switches with the Get-SPBackupHistory request, the cmdlet returns the history data for all backup and restore operations.
Now that you have successfully run the Get-SPBackupHistory
cmdlet, let’s talk about its output and what you can do with it. A
review of its output demonstrates why PowerShell makes command line
administration in SharePoint 2010 so much better. Because Get-SPBackupHistory
returns an array of all backup and restore operations run in the target
directory, it provides much more useful and manageable data than what
was available with similar commands in previous versions of SharePoint.
This means you don’t have to transform the cmdlet’s output into a
useable format first if you want to extract pertinent data from it with a
scripted process; it’s already in such a format. And thanks to
PowerShell’s pipelining capabilities, you can do things like pass its
output right into a query to select the most recent successful backup,
and then pass the BackupID for that instance directly to Restore-SPFarm. The result: in one line of PowerShell script, you can use Get-SPBackupHistory to automatically restore your most recent backup.