My notes and ramblings, normally about automation

PowerCLI - Configuring the Host Graphics Settings

· Read in about 2 min · (260 Words)
PowerCLI PowerShell VMware

There was an interesting ask the other day about whether or not PowerCLI could configure an ESXi host’s «Host Graphics Settings». I haven’t done much with GPUs, so this was the perfect reason to dig in to something new!

If you were to modify this setting in the UI, it would look something like the following: PowerCLI - Host Graphics Setting

I knew PowerCLI didn’t have any high-level cmdlets to do this, so it was time to start digging through the API docs to see what was possible.

There’s a Managed Object of ‘HostGraphicsManager’ which has a method of: ‘UpdateGraphicsConfig’ That method is looking for an of object of type: HostGraphicsConfig That object has a property of ‘deviceType’ which accepts deviceId and a graphicsType. GraphicsType is the property we’re looking to change, and it accepts the following inputs: ‘shared’ and ‘sharedDirect’

It sounds complex but, considering how many different specifications are needed to update some other host configurations, I think this one is pretty straight forward.

Translating the above into PowerCLI code will look a bit like the following:

# Store the desired ESXi host in a variable
$vmh = get-vmhost -name vmhostName

# Store the ESXi host's Graphics Manager object in a variable
$graphManager = Get-View $vmh.ExtensionData.ConfigManager.GraphicsManager

# Create a new Host Graphics Config specification
$graphConfigSpec = New-Object VMware.Vim.HostGraphicsConfig

# Configure the Host Graphics Config specification to the desired setting
# NOTE: 'shared' or 'sharedDirect' are the acceptable settings
$graphConfigSpec.HostDefaultGraphicsType = 'sharedDirect'
$graphConfigSpec.SharedPassthruAssignmentPolicy = $graphManager.GraphicsConfig.SharedPassthruAssignmentPolicy

# Apply the specification to the host
# NOTE: host must be rebooted for change to take effect
$graphManager.UpdateGraphicsConfig($graphConfigSpec)