Associate a Storage Policy with a Virtual Machine and Its Hard Disk

You can associate a storage policy with a virtual machine and its hard disk and check if they are compliant with the policy.

Prerequisites

  • Verify that you are connected to a vCenter Server system.
  • Verify that a storage policy named Str-Policy exists in the vCenter Server environment.
  • Verify that a virtual machine named Target-VM exists in the vCenter Server environment.

Procedure

  1. Get the Str-Policy storage policy and store it in the $policy variable.
    $policy = Get-SpbmStoragePolicy -Name 'Str-Policy'
  2. Get the Target-VM virtual machine and store it in the $vm variable.
    $vm = Get-VM -Name 'Target-VM'
  3. Get the hard disk associated with the $vm virtual machine and store it in the $hd variable.
    $hd = Get-HardDisk -VM $vm
  4. Assign the $policy storage policy to the $vm virtual machine and the $hd hard disk.
    Set-SpbmEntityConfiguration $vm, $hd -StoragePolicy $policy
  5. View the $policy storage policy's compliance with the $vm virtual machine and the $hd hard disk.
    Get-SpbmEntityConfiguration $vm, $hd
    Note: The storage policy can be compliant only if the datastore on which the virtual machine and hard disk are created is compliant with the storage policy.