«

»

May 31

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

About the author

vHersey

Hersey Cartwright is an IT professional with extensive experience designing, implementing, managing, and supporting technologies that improve business processes. Hersey is Solutions Architect for SimpliVity covering Virginia, Washington DC, and Maryland. He holds the VMware Certified Design Expert (VCDX-DV #128) certification. Hersey actively participates in the VMware community and was awarded the VMware vExpert title in 2016, 2015, 2014, 2013, and 2012. He enjoys working with, teaching, and writing about virtualization and other data center technologies. Follow Hersey on Twitter @herseyc

1 comment

1 ping

  1. Gary

    Hello, very helpful script thanks. Is there a way to modify the script to set more than one advanced configuration – I need to set about 10. I think I need to use an array but I’m unsure of the syntax…

  1. Configuring Virtual Machine vmware.log File Rotation | vHersey

    […] out this post on Setting/Modifying Advanced VM Options using PowerCLI to set these with […]

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

4 × five =