In our last article we demonstrated how to use the new vSphere PowerCLI 5.8 SPBM cmdlets to create vSphere Storage Policies. In this article we will demonstrate how to quickly associate a vSphere Storage Policy with a new or existing VM.
Example Provisioning Scenario
To illustrate how to leverage PowerCLI to associate vSphere Storage Policies with VMs we will continue with the provisioning example from our previous article.
- Virtual machine
- Single virtual disk
- Virtual SAN datastore
Follow these links for more information on creating vSphere Storage Policies for Virtual SAN:
Previously in order to create, manage, and associate vSphere Storage Policies with VMs using PowerCLI, one would need to leverage an intermediary method as well (e.g. Esxcli, RVC, REST API, etc). Often this could require the use of third party applications to bridge the gap in interfacing with the vSphere Storage Policy Based Management service. This resulted in added complexities and additional processing time for workflows that were automated with PowerCLI.
With the new PowerCLI 5.8 cmdlets for vSphere Storage Policy Based Management we are able to greatly reduce the complexity of vSphere Storage Policies with PowerCLI now by using PowerCLI exclusively. In the example below, we will demonstrate how to enhance the VM provisioning process by associating a vSphere Storage Policy with a virtual machine.
Associate vSphere Storage Policy with a virtual machine
We can use the new “Set-SpbmEntityConfiguration” PowerCLI cmdlet to assign a vSphere Storage Policy to a VM.
Get-VM -Name "VM1" | <b>Set-SpbmEntityConfiguration</b> -<b>StoragePolicy</b> "GoldPolicy"
$VM = "VM1"
$StoragePolicy = "GoldPolicy<i>"</i>
Get-VM -Name $VM | <b>Set-SpbmEntityConfiguration -StoragePolicy </b>$StoragePolicy
This will direct the vSphere Storage Policy Based Management service to begin managing storage SLAs for our new or existing virtual machine.
Validating Storage Policies
After assigning, we can then use the Get-SpbmEntityConfiguration cmdlet to validate the association. In the image below we can see our example virtual machine (VM1) now has the “GoldPolicy” associated with it.
Associating a vSphere Storage Policy with a virtual machine is that quick and easy! This is only the tip of the iceberg though. There is much more that can be quickly automated with the new PowerCLI 5.8 cmdlets vSphere Storage Policy Based Management. Stay tuned as we have many more articles with examples on their way!
- vSphere Storage Policy Based Management Overview – Part1
- vSphere Storage Policy Based Management Overview – Part 2
- vSphere PowerCLI 5.8 SPBM Walkthrough – Part 1: Introduction
- vSphere PowerCLI 5.8 SPBM – Part2: Creating vSphere Storage Policies
- Download and Install PowerCLI 5.8 Release 1
- Download and Install PowerCLI for vCD and vCloud Air Tenants 5.8 Release 1
- VMware vSphere PowerCLI 5.8 Release 1 Cmdlet Reference
- VMware PowerCLI Blog: 5.8 Release 1 Announcement
- VMware vSphere PowerCLI 5.8 Release 1 Release Notes
- VMware PowerCLI 5.8 Release 1 Changelog
- VMware PowerCLI Community Pages
- Storage Policy Based Management (SPBM) Configuration Maximums (2062751)