1. Use New-VM with Set-SpbmEntityConfiguration to set the policy
Result: Works on VM Home Namespace only.
PS C:\Users\chogan>New-VM -Name 30julytest3 -Datastore vsanDatastore \ -ResourcePool CH-Cluster | Set-SpbmEntityConfiguration -StoragePolicy RAID-5 Entity Storage Policy Status Time Of Check ------ -------------- ------ ------------- 30julytest3 RAID-5 compliant 7/30/2018 9:38:12 AM PS C:\Users\chogan>Get-VM -Name 30julytest3 | Get-SpbmEntityConfiguration Entity Storage Policy Status Time Of Check ------ -------------- ------ ------------- 30julytest3 RAID-5 compliant 7/30/2018 9:38:12 AM PS C:\Users\chogan>Get-VM -Name 30julytest3 | Get-Harddisk | Get-SpbmEntityConfiguration Entity Storage Policy Status Time Of Check ------ -------------- ------ ------------- Hard disk 1 vSAN Default Storage Policy compliant 7/30/2018 9:38:07 AM
2. Use New-VM with -AdvancedOption to set the policy
Result: Works for both VM Home Namespace and Hard Disks.
PS C:\Users\chogan>$policy = Get-SpbmStoragePolicy RAID-5 PS C:\Users\chogan>echo $policy Name Description AnyOfRuleSets CommonRule ---- ----------- ------------- ---------- RAID-5 {(VSAN.hostFailuresToTolera... {} PS C:\Users\chogan>New-VM -Name 30julytest1 -Datastore vsanDatastore \ -ResourcePool CH-Cluster -AdvancedOption $policy Name PowerState Num CPUs MemoryGB ---- ---------- -------- -------- 30julytest1 PoweredOff 1 0.250 PS C:\Users\chogan> Get-VM -Name 30julytest1 | Get-SpbmEntityConfiguration Entity Storage Policy Status Time Of Check ------ -------------- ------ ------------- 30julytest1 RAID-5 compliant 7/30/2018 8:50:07 AM PS C:\Users\chogan> Get-VM -Name 30julytest1 | Get-Harddisk | Get-SpbmEntityConfiguration Entity Storage Policy Status Time Of Check ------ -------------- ------ ------------- Hard disk 1 RAID-5 compliant 7/30/2018 8:50:07 AM
3. Use New-VM (clone from template) with Set-SpbmEntityConfiguration to set the policy
Result: Works on VM Home Namespace only. Same as #1.
4. Use New-VM (clone from template) with -AdvancedOption to set the policy
Result: Doesn’t work at all. Both VM Home Namespace and Hard Disk get default policy, not requested policy.
PS C:\Users\chogan>$policy = Get-SpbmStoragePolicy RAID-5 PS C:\Users\chogan>echo $policy Name Description AnyOfRuleSets CommonRule ---- ----------- ------------- ---------- RAID-5 {(VSAN.hostFailuresToTolera... {} PS C:\Users\chogan> New-VM -Name 30julytest2 -Template win7-desktop-orig \ -Datastore vsanDatastore -ResourcePool CH-Cluster -AdvancedOption $policy Name PowerState Num CPUs MemoryGB ---- ---------- -------- -------- 30julytest2 PoweredOff 1 2.000 PS PS C:\Users\chogan> Get-VM -Name 30julytest2 | Get-SpbmEntityConfiguration Entity Storage Policy Status Time Of Check ------ -------------- ------ ------------- 30julytest2 vSAN Default Storage Policy compliant 7/30/2018 9:31:04 AM PS PS C:\Users\chogan> Get-VM -Name 30julytest2 | Get-Harddisk | Get-SpbmEntityConfiguration Entity Storage Policy Status Time Of Check ------ -------------- ------ ------------- Hard disk 1 vSAN Default Storage Policy compliant 7/30/2018 9:31:04 AM
5. Multi-command solution using New-VM (clone from template) with Set-SpbmEntityConfiguration to set the policy
Result: It works, but it is not ideal since the VM is first created with one policy and needs to be rebuilt with a new policy, which leads to resync traffic.
PS C:\Users\chogan> New-VM -Name 30julytest -Template win7-desktop-orig \ -Datastore vsanDatastore -ResourcePool CH-Cluster Name PowerState Num CPUs MemoryGB ---- ---------- -------- -------- 30julytest PoweredOff 1 2.000 PS PS C:\Users\chogan> Get-VM -Name 30julytest | Get-SpbmEntityConfiguration Entity Storage Policy Status Time Of Check ------ -------------- ------ ------------- 30julytest vSAN Default Storage Policy compliant 7/30/2018 11:54:04 AM PS PS C:\Users\chogan> Get-VM -Name 30julytest | Get-Harddisk | \ Get-SpbmEntityConfiguration Entity Storage Policy Status Time Of Check ------ -------------- ------ ------------- Hard disk 1 vSAN Default Storage Policy compliant 7/30/2018 11:54:12 AM PS C:\Users\chogan> Get-VM -Name 30julytest | Set-SpbmEntityConfiguration \ -StoragePolicy RAID-5 Entity Storage Policy Status Time Of Check ------ -------------- ------ ------------- 30julytest RAID-5 compliant 7/30/2018 11:54:28 AM PS C:\Users\chogan> Get-VM -Name 30julytest | Get-Harddisk | \ Set-SpbmEntityConfiguration -StoragePolicy RAID-5 Entity Storage Policy Status Time Of Check ------ -------------- ------ ------------- Hard disk 1 RAID-5 compliant 7/30/2018 11:55:27 AM PS C:\Users\chogan> Get-VM -Name 30julytest | Get-SpbmEntityConfiguration Entity Storage Policy Status Time Of Check ------ -------------- ------ ------------- 30julytest RAID-5 compliant 7/30/2018 11:54:28 AM PS C:\Users\chogan> Get-VM -Name 30julytest | Get-Harddisk | \ Get-SpbmEntityConfiguration Entity Storage Policy Status Time Of Check ------ -------------- ------ ------------- Hard disk 1 RAID-5 compliant 7/30/2018 11:55:27 AM
6. Single command solution using New-VM with Set-SpbmEntityConfiguration to set the policy
Result: Sort of works. The following can be used so long as there is more than one disk attached to the VM. It doesn’t work when there is only a single disk.
PS C:\Users\chogan> New-VM -Name 30julytest6 -Datastore vsanDatastore \ -ResourcePool CH-Cluster -DiskGB 1,2 -AdvancedOption \ (Get-SpbmStoragePolicy RAID-5) | %{((Get-HardDisk -VM $_) + $_)} | \ Set-SpbmEntityConfiguration -StoragePolicy RAID-5 Entity Storage Policy Status Time Of Check ------ -------------- ------ ------------- Hard disk 1 RAID-5 compliant 7/30/2018 2:26:54 PM Hard disk 2 RAID-5 compliant 7/30/2018 2:26:59 PM 30julytest6 RAID-5 compliant 7/30/2018 2:27:02 PM
7. Single command solution using New-VM (clone from template) with Set-SpbmEntityConfiguration to set the policy
Result: Same as #6 – sort of works. The following can be used so long as there is more than one disk attached to the VM. It doesn’t work when there is only a single disk.
PS C:\Users\chogan> New-VM -Name 30julytest5 -Template win7-desktop-orig -Datastore \ vsanDatastore -ResourcePool CH-Cluster -OSCustomizationSpec win7 -AdvancedOption \ (Get-SpbmStoragePolicy RAID-5) | %{((Get-HardDisk -VM $_) + $_)} | \ Set-SpbmEntityConfiguration -StoragePolicy RAID-5 Entity Storage Policy Status Time Of Check ------ -------------- ------ ------------- Hard disk 1 RAID-5 compliant 7/30/2018 2:49:34 PM Hard disk 2 RAID-5 compliant 7/30/2018 2:49:39 PM 30julytest5 RAID-5 compliant 7/30/2018 2:49:44 PM
8. Single command solution using New-VM (clone from template) with Set-SpbmEntityConfiguration to set the policy
Result: This will work when there are one or more disks. But again, the initial VM is deployed with the default datastore policy, and then converted to the desired policy. Not ideal, as it incurs overhead to change the layout of the objects.
PS C:\Users\chogan> New-VM -Name 30julytest6 -Template win7-desktop-orig2 -Datastore \ vsanDatastore -ResourcePool CH-Cluster -OSCustomizationSpec win7 -AdvancedOption \ (Get-SpbmStoragePolicy RAID-5) | %{(@() + (Get-HardDisk -VM $_) + $_)} | \ Set-SpbmEntityConfiguration -StoragePolicy RAID-5 Entity Storage Policy Status Time Of Check ------ -------------- ------ ------------- Hard disk 1 RAID-5 compliant 7/31/2018 8:56:31 AM 30julytest6 RAID-5 compliant 7/31/2018 8:56:35 AM PS C:\Users\chogan> New-VM -Name 30julytest5 -Template win7-desktop-orig -Datastore \ vsanDatastore -ResourcePool CH-Cluster -OSCustomizationSpec win7 -AdvancedOption \ (Get-SpbmStoragePolicy RAID-5) | %{(@() + (Get-HardDisk -VM $_) + $_)} | \ Set-SpbmEntityConfiguration -StoragePolicy RAID-5 Entity Storage Policy Status Time Of Check ------ -------------- ------ ------------- Hard disk 1 RAID-5 compliant 7/31/2018 8:31:56 AM Hard disk 2 RAID-5 compliant 7/31/2018 8:32:02 AM 30julytest5 RAID-5 compliant 7/31/2018 8:32:07 AM PS C:\Users\chogan>
Summary
While it is possible to create a single line command to create a VM with a certain storage policy, but if that VM is cloned from a Template, the command is not intuitive. Kudos once again to Manish Tiwari who helped significantly with the more advanced commands. I am going to request that this process for cloning a VM from a Template with a policy gets simplified, and that some simpler PowerCLI commands should be available to simplify the creation of all VM objects with the same policy when it is cloned from a Template.