Hi,
i'm trying to create a script that configures the DiskSharesLevel per VM and per VM HardDisk.
Say i need to configure the value DiskSharesLevel to High for VM11 and VM1 has two hard disks, one with DiskSharesLevel value Low and one with DiskSharesLevel High, i can only touch the configuration for the hard disk with DiskSharesLevel Low.
Running the below gives me the HardDisk per VM that needs to be configured with the value specified in the $Disk1Shares:
#
#
$Disk1Shares="High"
#
$Tier1=get-vm | where {$_.CustomFields.item("Tier") -eq 1}
foreach ($vm in $Tier1) {
# Get the current DiskSharesLevel values for each VM
$vm_valuehash = Get-VM $vm | select HardDisks
$hd_confs = Get-VMResourceConfiguration -VM $vm | Select -ExpandProperty DiskResourceConfiguration
#Initialize the string to set resources
$set_vm_resource_string = ""
foreach($hd in $hd_confs){
$disk = @{"Name"=($vm_valuehash.HardDisks | where {$_.ExtensionData.Key -eq $hd.Key} | Select -ExpandProperty Name);"DiskSharesLevel"=$hd.DiskSharesLevel}
if ($disk.DiskSharesLevel -ne $Disk1Shares) {
$set_vm_resource_string += " -Disk " + $disk.Name + " -DiskSharesLevel $Disk1Shares"
}
}
}
The output for two VMs (VM1 has 1 HardDisk and VM2 has three HardDisks but only two needs to be reconfigured) looks like this:
-Disk Hard disk 1 -DiskSharesLevel High
-Disk Hard disk 1 -DiskSharesLevel High -Disk Hard disk 3 -DiskSharesLevel High
How can i use the values in $set_vm_resource_string to actually configure the DiskSharesLevel per HardDisk and VM?
i have, without any luck, tried:
get-vm $vm |Get-VMResourceConfiguration |Set-VMResourceConfiguration $set_vm_resource_string
¨Thanks in advanced