Powershell, not only Microsoft …

0 Flares Filament.io 0 Flares ×

PowerCLII reckon, that Powershell is one of the best Mictosoft products. It came alive when Vista/Windows Server 2008 (codename Longhorn – who remembers this 🙂 ) were released. I’m great Powershell fan, it allows to manage many Microsoft products, but not only. Once, I had to change few options in VMWare environment: “Memory/CPU Hotplug” and “Check and upgrade Tools during power cycling” as on screen below

I could do that manually, but changing manually settings in over 5 virtual machines is simply waste of time.  Fortunately there is a set of powershell cmdlets for managing VMWare environment, it’s called PowerCLI – this has to be installed of course, however it exists and it’s very helpful for managing VMWare environment. All the information about PowerCLI you can find in vSphere PowerCLI Documentation or using powershell command

So I’ve written 3 simple functions to enable settings, that I need. So let’s go

First function enables hotadd memory, second one enables hotadd CPU and third one enables VM tools upgrade at machine power cycle. So let’s go throgh the last function line by line.

Using Get-VM command I’m getting the virtual machine object. Unfortunately property, I want to set, is not returned. You can find all properties and methods of virtual machine object using command Get-VM [virtual machine name] | Get-Member. So I’m getting the vSphere view of virtual machine using Get-View command. Next line

While I was writing this script and trying to access specific properties I’ve learnt that there is a data object VMware.Vim.VirtualMachineConfigSpec, where one can set the virtual machin options, so I’m creating an object this type. And again I used Get-Member cmdlet to find the Tools propery of the type VMWare.Vim.ToolsConfigInfo
So I’m creating another object

This object has already property I need, I have learnt, by changing setting in vSphere, that property I need to set is toolsUpgradePolicy and it’s value should be set to upgradeAtPowerCycle

So setting is defined, time to apply it on virtual machine. In the vSphere view there is a method ReconfigVM(), which takes a VMware.Vim.VirtualMachineConfigSpec object as a parameter, so I’m reconfiguring VM and that’s it.

Now I can use these functions as many times and in as many scripts as I want.

0 Flares LinkedIn 0 Google+ 0 Facebook 0 Twitter 0 Filament.io 0 Flares ×

Leave a Reply

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