Hello,
I have scoured the internet looking for a way to do this. It was easy enough in the older powercli versions but since they took out the "Set-VMVideoMemory cmdlet out I am at a loss here. I have the rest of this day to get this figured out for a maintenance window tonight at 1am MST and I'm back to square one after realizing that cmdlet is no longer valid. Because every search I do points to using this command. Nothing recent without it. This is basically what I'm trying to do. The powering down of only the machines in the specified folder is working but I don't know what to use for changing the video settings. I really am drowning here. I am not a scripting person for powercli and this is my first attempt at it. I was fine until I found out that the cmdlet I was working with is no longer valid. The text in RED is the cmdlet that is no longer valid in powercli.
$vmservers=get-vm -location “lab” | Where-Object {$_.powerstate -eq ‘PoweredOn’}
$vmservers |select Name | export-csv C:\Users\lab1\Desktop\servers.csv -NoTypeInformation
$vmservers | Shutdown-VMGuest -Confirm:$false
$servers = import-csv C:\Users\lab1\Desktop\servers.csv | select -ExpandProperty name
Set-VMVideoMemory -VM $servers -MemoryMB 4000 -AutoDetect $false
$serversON = import-csv C:\Users\lab1\Desktop\servers.csv | select -ExpandProperty name
Start-VM -VM $serversON
Try something like this, it will change the Video RAM to 4GB
$vms = Get-VM -Location 'lab' | where{$_.PowerState -eq 'PoweredOn'}
$vms | Shutdown-VMGuest -Confirm:$false
while($vms.PowerState -contains 'PoweredOn'){
sleep 5
$vms = Get-VM $vms
}
Get-VM -Location 'lab' | %{
$vid = $_.ExtensionData.Config.Hardware.Device | ?{$_.GetType().Name -eq "VirtualMachineVideoCard"}
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$devChange = New-Object VMware.Vim.VirtualDeviceConfigSpec
$devChange.Operation = 'edit'
$vid.VideoRamSizeInKB = 4MB/1KB
$devChange.Device += $vid
$spec.DeviceChange += $devChange
$_.ExtensionData.ReconfigVM($spec)
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try something like this, it will change the Video RAM to 4GB
$vms = Get-VM -Location 'lab' | where{$_.PowerState -eq 'PoweredOn'}
$vms | Shutdown-VMGuest -Confirm:$false
while($vms.PowerState -contains 'PoweredOn'){
sleep 5
$vms = Get-VM $vms
}
Get-VM -Location 'lab' | %{
$vid = $_.ExtensionData.Config.Hardware.Device | ?{$_.GetType().Name -eq "VirtualMachineVideoCard"}
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$devChange = New-Object VMware.Vim.VirtualDeviceConfigSpec
$devChange.Operation = 'edit'
$vid.VideoRamSizeInKB = 4MB/1KB
$devChange.Device += $vid
$spec.DeviceChange += $devChange
$_.ExtensionData.ReconfigVM($spec)
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you so much LucD! This worked like a charm. The only part I needed to add to make it successful was to the autodetact. Other than that it worked great! Also, I added a call-out to give the results after it's been changed at the end.
$vms = Get-VM -Location 'lab' | where{$_.PowerState -eq 'PoweredOn'}
$vms | Shutdown-VMGuest -Confirm:$false
while($vms.PowerState -contains 'PoweredOn'){
sleep 5
$vms = Get-VM $vms
}
Get-VM -Location 'lab' | %{
$vid = $_.ExtensionData.Config.Hardware.Device | ?{$_.GetType().Name -eq "VirtualMachineVideoCard"}
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$devChange = New-Object VMware.Vim.VirtualDeviceConfigSpec
$devChange.Operation = 'edit'
$vid.VideoRamSizeInKB = 4MB/1KB
$vid.UseAutoDetect = $false
$devChange.Device += $vid
$spec.DeviceChange += $devChange
$_.ExtensionData.ReconfigVM($spec)
}
Get-VM -Location 'lab' | %{
$vid = $_.ExtensionData.Config.Hardware.Device | ?{$_.GetType().Name -eq "VirtualMachineVideoCard"}
write-host "$($_.name) Video Mem:" -foregroundcolor green
write-host "`tVideoRamSizeInKB: $($vid.VideoRamSizeInKB)"
write-host "`t UseAutoDetect: $($vid.UseAutoDetect)"
}
Is the VM powered off?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Afaik, the VMs should be powered off.
Was the 1st one you tried it with, not powered off?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
With one VM script powered it off, then reconfigured.
You should do the same with the 2 VMs
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
No, the original answer in this thread first looks for all powered on VMs in the folder.
Then it powers down those VMs, and waits till the power off is complete.
Then the video ram is changed for all VMs in the folder.
It's one script, with those 2 steps.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I figured it out. Added sleep command between shutdown and change.
Thank you Luc!
Hey LucD,
How would I add to this script to also increase the number of displays from 1 to 4?
Thanks in advanced!
On the VirtualMachineVideoCard object ($vid in the script) there is a property numDisplays.
You would need to assign the appropriate value to that property
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference