Last active
May 3, 2024 20:18
-
-
Save Zsoldier/324aa88abc12be154e1b9a9c9ce28bdb to your computer and use it in GitHub Desktop.
Change VSAN storage policy on one or more VMs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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