Page 2 of 2

PowerCLI VMtools Update on Reboot

Easy task for today was to set all the virtual machines to auto update the VMware tools on next reboot, we could of course manually use the webclient on each virtual machine but that is a bit time consuming, so we may as well use some PowerCLI to get the job done.

Here is some quick code to do the job.

1
2
3
4
5
6
7
Foreach ($VMS in (Get-VM)) {
$VM = $VMS | Get-View
$VMConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$VMConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
$VMConfigSpec.Tools.ToolsUpgradePolicy = "UpgradeAtPowerCycle"
$VM.ReconfigVM($vmConfigSpec)
}

 

 

 

 

PowerCli Eager Zero To Thin

Well job for today was to convert a load of virtual machines from good old eager zero to thin, now the hard way to do this is to do every one individually by hand.. As you can imagine that not exactly a good use of our time so lets automate this process and give ourselves some time for a coffee instead.

The code below is really very basic but does the job, its a straight forward storage vMotion between 2 datastores to do the conversion process and then a nice move back to the original store (in essence we are using the $THINSTORE as a bit of a buffer).

1
2
3
4
5
6
7
8
9
10
11
12
$THICKSTORE = "thick"
$THINSTORE = "thin"
$VMs = Get-datastore | Where {$_.name -like $THICKSTORE } | Get-VM

Foreach ($VM in $VMs){
Write-Host "VM: "$VM "Moving from: "$THICKSTORE "To: " $THINSTORE
Move-VM $VM -Datastore $THINSTORE -DiskStorageFormat Thin

# NOW its Thin move it back to original store
Write-Host "VM: "$VM "Moving from: "$THINSTORE "To: " $THICKSTORE
Move-VM $VM -Datastore $THICKSTORE
}

Well it seems to have done the trick so guess i am due that coffee now.

Newer posts »