VMware Cloud Community
sjesse
Leadership
Leadership
Jump to solution

Set Video Ram

    I can't see whats wrong, I'm trying to use

http://www.virtu-al.net/2011/03/10/change-vm-video-memory/

and I have the function in the script and I'm calling like the example

Get-VM AutoGLD | Set-VMVideoMemory -MemoryMB 128 -NumDisplays 4 -AutoDetect $false

but I'm getting

PS C:\Users\sjesse\Desktop\build-parent> Get-VM AutoGLD | Set-VMVideoMemory -MemoryMB 128 -NumDisplays 4 -AutoDetect $false

Set-VMVideoMemory : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its

properties do not match any of the parameters that take pipeline input.

At line:1 char:18

+ ... M AutoGLD | Set-VMVideoMemory -MemoryMB 128 -NumDisplays 4 -AutoDetec ...

+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidArgument: (AutoGLD:PSObject) [Set-VMVideoMemory], ParameterBindingException

    + FullyQualifiedErrorId : InputObjectNotBound,Set-VMVideoMemory

The function is below, and it looks correct so I'm not sure why I'm getting this error.

function Set-VMVideoMemory {

<# .SYNOPSIS   Changes the video memory of a VM .DESCRIPTION   This function changes the video memory of a VM .NOTES   Source: http://virtu-al.net   Author: Alan Renouf   Version: 1.1 .PARAMETER VM   Specify the virtual machine .PARAMETER MemoryMB   Specify the memory size in MB .EXAMPLE   PS> Get-VM VM1 | Set-VMVideoMemory -MemoryMB 4 -AutoDetect $false

#>

  Param (

    [parameter(valuefrompipeline = $true, mandatory = $true, HelpMessage = "Enter a vm entity")]

    [VMware.VimAutomation.ViCore.Impl.V1.Inventory.VirtualMachineImpl]$VM,

    [int64]$MemoryMB,

   [bool]$AutoDetect,

   [int]$NumDisplays

   )

  Process {

   $VM | Foreach {

      $VideoAdapter = $_.ExtensionData.Config.Hardware.Device | Where {$_.GetType().Name -eq "VirtualMachineVideoCard"}

      $spec = New-Object VMware.Vim.VirtualMachineConfigSpec

      $Config = New-Object VMware.Vim.VirtualDeviceConfigSpec

      $Config.device = $VideoAdapter

      If ($MemoryMB) {

         $Config.device.videoRamSizeInKB = $MemoryMB * 1KB

      }

      If ($AutoDetect) {

         $Config.device.useAutoDetect = $true

      } Else {

         $Config.device.useAutoDetect = $false

      }

      Switch ($NumDisplays) {

         1{ $Config.device.numDisplays = 1}

         2{ $Config.device.numDisplays = 2}

         3{ $Config.device.numDisplays = 3}

         4{ $Config.device.numDisplays = 4}

         Default {}

      }

      $Config.operation = "edit"

      $spec.deviceChange += $Config

      $VMView = $_ | Get-View

      Write-Host "Setting Video Display for $($_)"

      $VMView.ReconfigVM($spec)

   }

  }

}

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

I suspect Alan's function pre-dates the introduction of strong typing for PowerCLI's .NET objects.

See PowerCLI Best Practice: Correct Use of Strong Typing

Try changing the parameter type from [VMware.VimAutomation.ViCore.Impl.V1.Inventory.VirtualMachineImpl] to [VMware.VimAutomation.ViCore.Types.V1.Inventory.VirtualMachine]


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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

I suspect Alan's function pre-dates the introduction of strong typing for PowerCLI's .NET objects.

See PowerCLI Best Practice: Correct Use of Strong Typing

Try changing the parameter type from [VMware.VimAutomation.ViCore.Impl.V1.Inventory.VirtualMachineImpl] to [VMware.VimAutomation.ViCore.Types.V1.Inventory.VirtualMachine]


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

0 Kudos
sjesse
Leadership
Leadership
Jump to solution

Yep that was it, thank you.

0 Kudos