2008-11-16

Changing Custom Notes on Virtual Machines

I wanted to do a bit of housekeeping for all the VM's floating around.

I got to the state that there are machines that I do not know who they belong to, when they were installed and who is the responsible party in case the **** hits the fan.

That is where the VI toolkit comes to the rescue !!

What I did was added to addiditonal fields for each machine.

1. Owner
2. Date installed

This was pretty each to do both

Create the field

Get-cluster <Clustername>| get-vm | New-CustomField -name Owner
Get-cluster <Clustername>| get-vm | New-CustomField -name "Date installed"


Now to populate the field you would use

get-vm <VM Name>| Set-CustomField -name Owner -value "Whatever you want"

Now say you don't know which property it is you would like to update, well that you can get from running this command:

PS C:\Program Files\VMware\Infrastructure\VIToolkitForWindows> get-vm <VM Name>| Get-View


Capability           : VMware.Vim.VirtualMachineCapability
Config               : VMware.Vim.VirtualMachineConfigInfo
Layout               : VMware.Vim.VirtualMachineFileLayout
EnvironmentBrowser   : VMware.Vim.ManagedObjectReference
ResourcePool         : VMware.Vim.ManagedObjectReference
ResourceConfig       : VMware.Vim.ResourceConfigSpec
Runtime              : VMware.Vim.VirtualMachineRuntimeInfo
Guest                : VMware.Vim.GuestInfo
Summary              : VMware.Vim.VirtualMachineSummary
Datastore            : {VMware.Vim.ManagedObjectReference}
Network              : {VMware.Vim.ManagedObjectReference}
Snapshot             :
GuestHeartbeatStatus : green
Parent               : VMware.Vim.ManagedObjectReference
CustomValue          : {10}
OverallStatus        : green
ConfigStatus         : green
ConfigIssue          : {}
EffectiveRole        : {-1}
Permission           : {}
Name                 : <VM Name>
DisabledMethod       : {Destroy_Task, UnregisterVM, RevertToCurrentSnapshot_Task, RemoveAllSnapshots_Task...}
RecentTask           : {}
DeclaredAlarmState   : {alarm-15.vm-3208, alarm-4.vm-3208, alarm-5.vm-3208}
TriggeredAlarmState  : {}
Value                : {10}
AvailableField       : {Date Installed, Owner}
MoRef                : VMware.Vim.ManagedObjectReference
Client               : VMware.Vim.VimClient


AvailableField       : {Date Installed, Owner} is what you are looking for. These are the fields that you are looking to update.

Thanks to LucD for pointing me in the right direction here and here.

My next step will be to create a script that will run daily, and update any VM that has not been populated with the date installed field - with the current date. Maybe even go as far as to send a reminder email to the Cluster Admin to update the owner in the correct field.

Will Let you know how it turns out.


No comments: