VMware PowerCLI Function to Modify Virtual Machine Configuration Options

This is a blog post I did on a different blog and I am am migrating most of the VMware/system admin posts here and this is the first.
—-

I was looking for a powershell script to set a few virtual machine security options for a school lab. The configuration keys I need to set are isolation.device.connectable.disable, isolation.device.edit.disable, and RemoteDisplay.maxConnections.

I found a function used to set RemoteDisplay.maxConnections here. By changing the RemoteDisplay.maxConnections it could be used to also change the other options so I modified the function to accept another parameter for the setting you want to add or change.

Here is the function:

Function Set-ExtraOptions{
param(
    [string[]]$vmName,
    [string[]]$KeyName,
    $KeyValue
)
    $vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec

    $extra = New-Object VMware.Vim.optionvalue
    $extra.Key="$KeyName"
    $extra.Value="$KeyValue"
    $vmConfigSpec.extraconfig += $extra

        $vm = Get-VM $vmName | Get-View
        $vm.ReconfigVM($vmConfigSpec)
}

And here is how you call it:

Set-ExtraOptions -vmName VM_NAME -KeyName KEY_NAME -KeyValue KEY_VALUE

To set isolation.device.connectable.disable to FALSE for LabVM-A just call the function like this:

Set-ExtraOptions -vmName “LabVM-A” -KeyName isolation.device.connectable.disable -KeyValue FALSE

2 thoughts on “VMware PowerCLI Function to Modify Virtual Machine Configuration Options

Leave a Reply

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

12 − 2 =