Changing the virtual videocard settings

By | May 6, 2011

Some time ago I was asked to create a script that could list each VM’s videocard settings.

$VMs = Get-View -ViewType VirtualMachine | sort Name 
foreach($VM in $VMs){
	write "$($VM.Name) $($VM.Guest.Screen.Width)/$($VM.Guest.Screen.Height)"
}

As you could see that was quite simple.
I using the Get-View -ViewType to speed up the query – See LucD’s post on http://communities.vmware.com/message/1511671#1511671 for more info.

Then I was asked to set all VM’s videocard setting to Auto Detect (Default setting).

$vms = Get-View -ViewType VirtualMachine | sort Name
foreach ($vm in $vms){
	if ($vm.Runtime.PowerState -eq "PoweredOff") {
		if ($vm.Config.Version -eq "vmx-07"){ 
			foreach($dev in $vm.Config.Hardware.Device){
				if ($dev.DeviceInfo.Label -like "Video*"){
					if ($dev.UseAutoDetect -match "False" ) {
						$VMName = $vm.Name
						$VMcidcrd = New-Object VMware.Vim.VirtualMachineVideoCard 
						$VMcidcrd.UseAutoDetect = 1
						$VMcidcrd.Key = 500
						$spec = new-object VMware.Vim.VirtualDeviceConfigSpec
						$spec.Device = $VMcidcrd
						$spec.Operation = "edit"
						$VMSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
						$VMSpec.DeviceChange = $spec
						$vm.ReconfigVM_Task($VMSpec)
						write "$($vm.Name) - Video Settings Changed"
						
					}
				}
			}
		}
	}
}

As you can see this requires a bit more.
The VM has to be
• Powered Off
• Running vHW version 7
Download the full script here.

If you want to set the videocard setting to a specific MB, then just change the line from the above script

$VMcidcrd.UseAutoDetect = 0

To

$VMcidcrd.UseAutoDetect = 0

And add the line

$VMcidcrd.VideoRamSizeInKB = 131072

Where the 131072 us the amount of MB you want multiplied with 1024
Ex. 128 x 1024 = 131072

One thought on “Changing the virtual videocard settings

Leave a Reply

Your email address will not be published. Required fields are marked *