One this that has always bugged me with vCenter UIs is seeing a reconfigure VM task but not being able to tell what was changed. Some times in an investigation this can be very important.
While looking at Event objects one day I discovered an attribute called configchanges on a reconfigured event object. In there are 3 text string called Modified,Added and Deleted. After a bit of tidying up (splitting them up by semi colons and removing the spaces) I was left with something I can work with.
So here is a quick script to read the most recent 150 VM Events looking for any reconfigure events. Once we have them the script will list out the details in a CSV.
Here is the Script
$Report = @()
# Im just getting all VMs. you can add something here so $VMs contains only the VMs you want.
$AllVMs = get-vm
foreach ($VM in $AllVMs)
{
# im just looking at the last 150 events but we could loook at time ranges
#$ReconfigEvts = $VM | Get-VIEvent -Start ((get-date).addhours(-$hours)) -Finish (get-date) | where{$_.FullFormattedMessage -match "Reconfigured"}
$ReconfigEvts = $VM | Get-VIEvent -MaxSamples 150 | where{$_.FullFormattedMessage -match "Reconfigured"}
foreach ($ReconfigEvt in $ReconfigEvts)
{
# confs will just be text so need to get them in at an array
$ConfChanges = $ReconfigEvt.configchanges.Modified.Split(";").trim()
$ConfAdds = $ReconfigEvt.configchanges.Added.Split(";").trim()
$ConfRemoves = $ReconfigEvt.configchanges.Deleted.Split(";").trim()
# one row for each bit of the reconfig Event modifications
foreach ($ConfChange in $ConfChanges)
{
if($ConfChange.length -gt 1)
{
$tempObj = "" | select VM,EventID,User,Date,Modified,Added,Deleted
$tempObj.VM = $VM.name
$tempObj.EventID = $ReconfigEvt.Key
$tempObj.User = $ReconfigEvt.UserName
$tempObj.Date = $ReconfigEvt.CreatedTime
$tempObj.Modified = $ConfChange
$tempObj.Added = ''
$tempObj.Deleted = ''
$Report += $tempObj
}
}
# one row for each bit of the reconfig Event Adds
foreach ($ConfAdd in $ConfAdds)
{
if($ConfAdd.length -gt 1)
{
$tempObj = "" | select VM,EventID,User,Date,Modified,Added,Deleted
$tempObj.VM = $VM.name
$tempObj.EventID = $ReconfigEvt.Key
$tempObj.User = $ReconfigEvt.UserName
$tempObj.Date = $ReconfigEvt.CreatedTime
$tempObj.Modified = ''
$tempObj.Added = $ConfAdd
$tempObj.Deleted = ''
$Report += $tempObj
}
}
# one row for each bit of the reconfig Event Deletions
foreach ($ConfRemove in $ConfRemoves)
{
if($ConfRemove.length -gt 1)
{
$tempObj = "" | select VM,EventID,User,Date,Modified,Added,Deleted
$tempObj.VM = $VM.name
$tempObj.EventID = $ReconfigEvt.Key
$tempObj.User = $ReconfigEvt.UserName
$tempObj.Date = $ReconfigEvt.CreatedTime
$tempObj.Modified = ''
$tempObj.Added = ''
$tempObj.Deleted = $ConfRemove
$Report += $tempObj
}
}
}
}
$Report | export-csv ".\VM_Config_Changes.csv" -NoTypeInformation
The output will show the following columns.
“VM”,”EventID”,”User”,”Date”,”Modified”,”Added”,”Deleted”
The following shows a simple CPU and memory modification.
“VM”,”EventID”,”User”,”Date”,”Modified”,”Added”,”Deleted”
“VM01″,”806356″,”jason”,”15/06/2020 18:10:31″,”config.hardware.numCPU: 1 -> 2″,””,””
“VM01″,”806356″,”jason”,”15/06/2020 18:10:31″,”config.hardware.memoryMB: 48 -> 2048″,””,””
“VM01″,”806356″,”jason”,”15/06/2020 18:10:31″,”config.cpuAllocation.shares.shares: 1000 -> 2000″,””,””
“VM01″,”806356″,”jason”,”15/06/2020 18:10:31″,”config.memoryAllocation.shares.shares: 480 -> 20480″,””,””
And save all that to a CSV file. Very handy.