Skip to content

Instantly share code, notes, and snippets.

@Zsoldier
Last active May 3, 2024 20:18
Show Gist options
  • Save Zsoldier/324aa88abc12be154e1b9a9c9ce28bdb to your computer and use it in GitHub Desktop.
Save Zsoldier/324aa88abc12be154e1b9a9c9ce28bdb to your computer and use it in GitHub Desktop.
Change VSAN storage policy on one or more VMs
#See storage policies available
Get-SpbmStoragePolicy
#Define storage policy you want to apply
$storagepolicyname = "RAID-1 FTT-1"
#Capture Storage policy object.
$storagepolicies = Get-SpbmStoragePolicy
$targetstoragepolicy = ($storagepolicies | where-object {$_.name -eq $storagepolicyname})
#Get Storage Policy configured on VM.
#It's important to note that a VM's storage policy (effectively configuration) can be different than that of it's associated vmdk's.
$vm = get-vm -name nakabuntu
get-spbmentityconfiguration -VM $vm
#Get Storage Policy configured on vmdk(s)
$vmhdds = get-vm -name nakabuntu | get-harddisk
get-spbmentityconfiguration -harddisk $vmhdds
#Change for a single VM
#This will overwrite all unique policies associated w/ VM individual disks as well to the one specified.
$vm = get-vm -name nakabuntu
set-vm $vm -StoragePolicy $targetstoragepolicy
#Change VM and VM Disk Storage Policies independently
$vm = get-vm -name nakabuntu
$vmdisks = $vm | get-harddisk
$storagepolicies = Get-SpbmStoragePolicy
set-vm $vm -storagepolicy ($storagepolicies | where-object {$_.name -eq "RAID-1 FTT-1"})
set-harddisk $vmdisks -storagepolicy ($storagepolicies | where-object {$_.name -eq "RAID-5 FTT-1"})
#Loop through multiple VMs to apply same policy.
#This will overwrite all unique policies associated w/ VM individual disks as well to the one specified.
$vms = get-vm
Foreach ($vm in $vms){
set-vm $vm -StoragePolicy $targetstoragepolicy
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment