Tip

Using PowerShell for bare-metal recovery

Over the last couple of versions of Windows Server, Microsoft has worked to make PowerShell ever more capable. One of the somewhat surprising things that you can do with PowerShell in Windows Server 2008 R2 and Windows Server 2012

Requires Free Membership to View

is create a backup that is suitable for performing a bare-metal recovery. In this article, I will show you how.

While you don't have to use PowerShell to create a bare-metal backup, Microsoft has stated that PowerShell is the preferred administrative interface for Windows Server and that GUI-based management will eventually become a thing of the past. Admins need to learn PowerShell now to avoid getting left behind.

Recovery operations are backup application-specific. This article is based around the use of the native Windows Server Backup application. There are other backup vendors that support command-line operations, but the required command set will vary from one vendor to the next.

With that said, you will have to prepare Windows Server by running the following commands in order to add the Windows Server Backup command set to PowerShell:

Add-PSSnapin Windows.ServerBackup

Windows Server 2012 will automatically load the required PowerShell modules, but if you are using Windows Server 2008 R2, then you need to use the Import All Modules command to load the required modules.

Adding bare metal recovery capabilities

The Windows Backup Policy dictates whether or not you can create or restore bare-metal recovery capable backups. Therefore, you must begin by determining whether not such a policy exists. To do so, enter the Get-WBPolicy cmdlet.

If you find that no Windows Backup Policy exists, then you will have to create one. To do so, enter the New-WBPolicy cmdlet.

Once a Windows Backup policy has been created, it must be modified in order to allow for bare-metal recovery. To make this modification, you must be a member of either the Administrators group or the Backup Operators group. Furthermore, the policy must be marked as editable before you can modify it.

If you just created a new Windows Backup policy using the New-WBPolicy cmdlet, then the new policy should already be flagged as editable. If not, then make it editable by entering the Get-WBPolicy cmdlet and appending the –Editable parameter.

Once the Windows Backup policy has been flagged as editable, you can add bare-metal recovery capabilities to the policy by using the Add-WBBareMetalRecovery cmdlet. When doing so, you will also need to append the –Policy attribute and the variable that represents your Windows Backup Policy. Typically you should be able to use the following command:

Add-WBBareMetalRecovery –Policy $policy

After adding bare-metal recovery capabilities to the Windows Backup policy, it is a good idea to verify that the operation was successful. The easiest way to do so is to use the Get-WBBareMetalRecovery cmdlet to view whether or not the policy has been provisioned for bare-metal recovery. The actual command used for doing so is:

Get-WBBareMetalRecovery –Policy $policy

Once you've created the Windows Backup policy, using it is surprisingly easy. You can run a one-off backup by using the Start-WBBackup cmdlet. When you do, simply tell Windows that you want to use the previously created policy. 

You will also typically need to specify a backup location, which is usually done by assigning a backup target to a variable by way of the New-WBBackupTarget cmdlet. After doing so, the Add-WBBackupTarget cmdlet is used to assign the specified backup target to the policy that you created earlier. For example, you might use the following commands to designate a backup target:

$BackupLocation = New=WBBackupTarget –VolumePath E:
Add-WBBackupTarget –Policy $Policy –Target $BackupLocation

Once you've specified a backup target, you can launch the backup process. To do so, you could use the following command:

Start-WBBackup –Policy $policy

Although this command manually launches a backup, it is just as easy to create a scheduled backup.

Putting it all together

Although I have explained how the various commands are used, I thought it might be helpful to provide you with a series of commands for creating a Windows Backup policy, provision it for bare-metal recovery and launch a backup. With that said, the following commands can be used:

$policy = New-WBpolicy
Add-WBBareMetalRecovery $policy
$BackupLocation = New-WBBackupTarget –VolumePath E:
Add-WBBackupTarget –Policy $Policy –Target $BackupLocation
Start-WBBackup –Policy $policy

In this article, I have shown you how to use PowerShell to create a backup that is suitable for bare-metal recovery. You can use similar techniques for other types of backups as well. Cmdlets such as Add-WBVolume, Add-WBFileSpec and Add-WBSystemState can be used to create other types of backups.

About the author:
Brien M. Posey, MCSE, has received Microsoft's MVP award for Exchange Server, Windows Server and Internet Information Server. Brien has served as CIO for a nationwide chain of hospitals and has been responsible for the department of information management at Fort Knox. You can visit Brien's personal website at www.brienposey.com.

This was first published in September 2013

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.