{"id":276,"date":"2020-07-29T00:13:23","date_gmt":"2020-07-28T23:13:23","guid":{"rendered":"http:\/\/192.168.8.14\/?p=276"},"modified":"2020-07-29T00:13:23","modified_gmt":"2020-07-28T23:13:23","slug":"report-vm-reconfigurations","status":"publish","type":"post","link":"https:\/\/www.jasonstreet.com\/?p=276","title":{"rendered":"Report VM reconfigurations"},"content":{"rendered":"\n<p>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.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>Here is the Script<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\n$Report = @()\n\n# Im just getting all VMs. you can add something here so $VMs contains only the VMs you want.\n$AllVMs = get-vm\n\n\nforeach ($VM in $AllVMs)\n{\n    # im just looking at the last 150 events but we could loook at time ranges\n    #$ReconfigEvts = $VM | Get-VIEvent -Start ((get-date).addhours(-$hours)) -Finish (get-date) | where{$_.FullFormattedMessage -match &quot;Reconfigured&quot;}\n    $ReconfigEvts = $VM | Get-VIEvent -MaxSamples 150 | where{$_.FullFormattedMessage -match &quot;Reconfigured&quot;}\n\n    foreach ($ReconfigEvt in $ReconfigEvts)\n    {\n        # confs will just be text so need to get them in at an array\n        $ConfChanges = $ReconfigEvt.configchanges.Modified.Split(&quot;;&quot;).trim()\n        $ConfAdds = $ReconfigEvt.configchanges.Added.Split(&quot;;&quot;).trim()\n        $ConfRemoves = $ReconfigEvt.configchanges.Deleted.Split(&quot;;&quot;).trim()\n\n        # one row for each bit of the reconfig Event modifications\n        foreach ($ConfChange in $ConfChanges)\n        {\n            if($ConfChange.length -gt 1)\n            {\n                $tempObj = &quot;&quot; | select VM,EventID,User,Date,Modified,Added,Deleted\n                $tempObj.VM       = $VM.name\n                $tempObj.EventID  = $ReconfigEvt.Key\n                $tempObj.User     = $ReconfigEvt.UserName\n                $tempObj.Date     = $ReconfigEvt.CreatedTime\n                $tempObj.Modified = $ConfChange\n                $tempObj.Added    = &#039;&#039;\n                $tempObj.Deleted  = &#039;&#039;\n                $Report += $tempObj\n            }\n        }\n\n        # one row for each bit of the reconfig Event Adds\n        foreach ($ConfAdd in $ConfAdds)\n        {\n            if($ConfAdd.length -gt 1)\n            {\n                $tempObj = &quot;&quot; | select VM,EventID,User,Date,Modified,Added,Deleted\n                $tempObj.VM       = $VM.name\n                $tempObj.EventID  = $ReconfigEvt.Key\n                $tempObj.User     = $ReconfigEvt.UserName\n                $tempObj.Date     = $ReconfigEvt.CreatedTime\n                $tempObj.Modified = &#039;&#039;\n                $tempObj.Added    = $ConfAdd\n                $tempObj.Deleted  = &#039;&#039;\n                $Report += $tempObj\n            }\n        }\n\n        # one row for each bit of the reconfig Event Deletions\n        foreach ($ConfRemove in $ConfRemoves)\n        {\n            if($ConfRemove.length -gt 1)\n            {\n                $tempObj = &quot;&quot; | select VM,EventID,User,Date,Modified,Added,Deleted\n                $tempObj.VM       = $VM.name\n                $tempObj.EventID  = $ReconfigEvt.Key\n                $tempObj.User     = $ReconfigEvt.UserName\n                $tempObj.Date     = $ReconfigEvt.CreatedTime\n                $tempObj.Modified = &#039;&#039;\n                $tempObj.Added    = &#039;&#039;\n                $tempObj.Deleted  = $ConfRemove\n                $Report += $tempObj\n            }\n        }\n    }\n}\n\n$Report | export-csv &quot;.\\VM_Config_Changes.csv&quot; -NoTypeInformation\n<\/pre><\/div>\n\n\n<p>The output will show the following columns. <\/p>\n\n\n\n<p>&#8220;VM&#8221;,&#8221;EventID&#8221;,&#8221;User&#8221;,&#8221;Date&#8221;,&#8221;Modified&#8221;,&#8221;Added&#8221;,&#8221;Deleted&#8221;<\/p>\n\n\n\n<p>The following shows a simple CPU and memory modification.<\/p>\n\n\n\n<p>&#8220;VM&#8221;,&#8221;EventID&#8221;,&#8221;User&#8221;,&#8221;Date&#8221;,&#8221;Modified&#8221;,&#8221;Added&#8221;,&#8221;Deleted&#8221;<br>&#8220;VM01&#8243;,&#8221;806356&#8243;,&#8221;jason&#8221;,&#8221;15\/06\/2020 18:10:31&#8243;,&#8221;config.hardware.numCPU: 1 -> 2&#8243;,&#8221;&#8221;,&#8221;&#8221;<br>&#8220;VM01&#8243;,&#8221;806356&#8243;,&#8221;jason&#8221;,&#8221;15\/06\/2020 18:10:31&#8243;,&#8221;config.hardware.memoryMB: 48 -> 2048&#8243;,&#8221;&#8221;,&#8221;&#8221;<br>&#8220;VM01&#8243;,&#8221;806356&#8243;,&#8221;jason&#8221;,&#8221;15\/06\/2020 18:10:31&#8243;,&#8221;config.cpuAllocation.shares.shares: 1000 -> 2000&#8243;,&#8221;&#8221;,&#8221;&#8221;<br>&#8220;VM01&#8243;,&#8221;806356&#8243;,&#8221;jason&#8221;,&#8221;15\/06\/2020 18:10:31&#8243;,&#8221;config.memoryAllocation.shares.shares: 480 -> 20480&#8243;,&#8221;&#8221;,&#8221;&#8221;<\/p>\n\n\n\n<p>And save all that to a CSV file. Very handy.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[5,4,43],"tags":[52,54,51,12,13,53,10,8,6],"class_list":["post-276","post","type-post","status-publish","format-standard","hentry","category-powercli","category-powershell","category-vmware","tag-change","tag-edit","tag-events","tag-powercli","tag-powershell","tag-reconfigure","tag-report","tag-vm","tag-vmware"],"_links":{"self":[{"href":"https:\/\/www.jasonstreet.com\/index.php?rest_route=\/wp\/v2\/posts\/276","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jasonstreet.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jasonstreet.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jasonstreet.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jasonstreet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=276"}],"version-history":[{"count":3,"href":"https:\/\/www.jasonstreet.com\/index.php?rest_route=\/wp\/v2\/posts\/276\/revisions"}],"predecessor-version":[{"id":296,"href":"https:\/\/www.jasonstreet.com\/index.php?rest_route=\/wp\/v2\/posts\/276\/revisions\/296"}],"wp:attachment":[{"href":"https:\/\/www.jasonstreet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=276"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jasonstreet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=276"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jasonstreet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=276"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}