I want to change the size of the memory of the video card of a VM, because the default 4 MB isn't enough for our VDI. I used the script below to do this, but it doesn't work.
What goes wrong? We have over 2000 virtual desktops, so using a script is the only way.
============================================
(square bracket begin)Reflection.Assembly(square bracket end)::LoadWithPartialName("VMware.Vim")
Function ChangeVideoCard ($vmview)
{
$videocard = New-Object VMware.Vim.VirtualMachineVideoCard
$videocard.videoRamSizeInKB = 8000
$videocard.key = 500
$virtdev = New-Object VMware.Vim.VirtualDeviceConfigSpec
$virtdev.Device = $videocard
$virtdev.Operation = "edit"
$vmSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmSpec.DeviceChange = $virtdev
$taskImpl = $vmview.ReconfigVM_Task($vmSpec)
$task = Get-View $taskImpl
while (($task.info.state -eq "running") -or ($task.info.state -eq "queued"))
{$task = Get-View $taskImpl}
if ($task.info.state -eq "error")
{
$task.info.state
$task.info.error
$task.info.error.Fault
}
else
{
$task.info.state
}
}
Get-VIServer -Server "ticv5vmg.prod.cbs.local" -User "Administrator" -Password "xxxx"
$vm = Get-VM "test1" | % {Get-View $_.ID}
foreach ($device in $vm.config.hardware.device)
{
if ($device.key -eq 500) {$device}
}
ChangeVideoCard ($vm)
============================================
Output:
GAC Version Location
False v2.0.50727 C:\Program Files\VMware\Infrastructure\VIToolkitForWindows\VMwar...
Name : ticv5vmg.prod.cbs.local
Port : 443
VideoRamSizeInKB : 4096
Key : 500
DeviceInfo : VMware.Vim.Description
Backing :
Connectable :
ControllerKey : 100
UnitNumber : 0
DynamicType :
DynamicProperty :
error
Fault : VMware.Vim.InvalidDeviceOperation
LocalizedMessage : Invalid operation for device '0'.
DynamicType :
DynamicProperty :
BadOp : edit
BadFileOp : create
DeviceIndex : 0
Property :
DynamicType :
DynamicProperty :