VMware Cloud Community
RashidRodriguez
Contributor
Contributor
Jump to solution

Need to Change Video settings on specific VM's in a folder

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

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

0 Kudos
14 Replies
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
RashidRodriguez
Contributor
Contributor
Jump to solution

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)"

}

0 Kudos
Arkady
Contributor
Contributor
Jump to solution

Hello Luc,

Used your script for one VM in a folder and worked great. But with 2 VMs in the folder getting an error during reconfiguring, attached the scren shot

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Is the VM powered off?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Arkady
Contributor
Contributor
Jump to solution

Both VMs are on
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
Arkady
Contributor
Contributor
Jump to solution

With one VM script powered it off, then reconfigured.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You should do the same with the 2 VMs


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Arkady
Contributor
Contributor
Jump to solution

Power off operation should be separate from this script?
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
Arkady
Contributor
Contributor
Jump to solution

I figured it out. Added sleep command between shutdown and change.

Thank you Luc!

0 Kudos
Jayjones723
Contributor
Contributor
Jump to solution

Hey LucD,

How would I add to this script to also increase the number of displays from 1 to 4?

Thanks in advanced!

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
Jayjones723
Contributor
Contributor
Jump to solution

Thanks Luc!
0 Kudos