vSAN Hyperconverged Infrastructure Software-Defined Storage Virtual Volumes (vVols)

Backup or Recover SPBM Profiles with PowerCLI

I work in the lab a lot.

One of the tasks that I often perform is:

  • Blowing away my VCSA (or Windows vCenter Server),
  • Redeploying it, and
  • Reattaching it to a cluster that is running vSAN.

As a result of a new VCSA deployment, only a few SPBM policies will be present. Any previously available SPBM polices are lost with the previous VCSA instance.

nopolicies

 

PowerCLI cmdlets

There is a PowerCLI cmdlet that will allow administrators to export SPBM policies. Basically the cmdlet is “Export the policy named ~whatever~ and put it in X folder

The named policy is exported as an xml file that looks something like this:
spbm-xml

 

The Import-SpbmStoragePolicy PowerCLI cmdlet allows administrators to import the SPBM xml.

These 2 cmdlets make it easy to download/upload an SPBM policy xml file.

What about multiple policies?

But what if you have many policies? These cmdlets work one policy at a time.

To export many policies, we’d need to enumerate the policies in vCenter.

Importing many policies would work the same way, but each policy would have to be passed to the cmdlet. The path and xml policy file names could be part of an array, or read directly from a directory.

Grabbing all the files in a path would look something like this:

To handle each of them, we can use Foreach again.

To see what each file contains, we’ll need to parse it.

The Result

After a little cleanup and error handling, the resulting script can allow the backup and recovery of storage policies into a new vCenter instance.

spbm2

The completed script can be found on the VMware Developer site at the following URL:
https://developercenter.vmware.com/samples?id=1661

Enjoy!

Reposted from http://www.jasemccarty.com/blog/spbm-backup-recover-w-powercli/