You can retrieve a datastore compatible with storage policy and create a virtual machine in the datastore.

Prerequisites

  • Verify that you are connected to a vCenter Server system.
  • Verify that a tag-based storage policy named Tag-Policy exists in the vCenter Server environment.
  • Verify that the tag of the Tag-Policy storage policy is associated with one of the available datastores in the vCenter Server environment.

Procedure

  1. Get the tag-based Tag-Policy storage policy and store it in the $policy variable.
    $policy = Get-SpbmStoragePolicy -Name 'Tag-Policy'
  2. Get the tag used in the Tag-Policy storage policy and store it in the $tag variable.
    $tag = ($($($policy.AnyOfRulesets).AllOfRules).AnyOfTags)[0]
  3. Get a datastore compatible with the $policy storage policy and store it in the $ds variable.
    $ds = Get-SpbmCompatibleStorage -StoragePolicy $policy
  4. Get the virtual machine host that contains the $ds datastore and store it in the $vmhost variable.
    $vmHost = Get-VMHost -Datastore $ds
  5. Create a virtual machine named VM-Tag in the $ds datastore and store the virtual machine object in the $vm variable.
    $vm = New-VM -Name 'VM-Tag' -ResourcePool $vmHost -Datastore $ds -NumCPU 2 -MemoryGB 4 -DiskMB 1
  6. Associate the $policy storage policy with the $vm virtual machine.
    Set-SpbmEntityConfiguration $vm -StoragePolicy $policy
  7. Verify that the $vm virtual machine is compliant with the $policy storage policy.
    Get-SpbmEntityConfiguration $vm
    The status should be Compliant.
  8. Get the Tag-Assignment object for the $ds datastore and store it in the $tagAs variable.
    $tagAs = Get-TagAssignment -Entity $ds
  9. Remove the $tag tag association from the $ds datastore.
    Remove-TagAssignment -TagAssignment $tagAs
  10. Check the compliance of the $vm virtual machine with the $policy storage policy.
    Get-SpbmEntityConfiguration $vm
    The status should be NonCompliant.