VMware Cloud Community
virtubhuvan
Contributor
Contributor

Finding the created date of my VMDK file

Can someone help me querying the created date of my VMDK files. I could somehow query the last modified date of my VMDK files; however, I don't see any decent way of finding the Created time stamp of the files that belong my VMs.

I have to query my VMs to find the recently added hard disks for an audit purpose.

Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership

You could look at the events to see when a configuration change for adding a harddisk  to the VM was done.
Also from the vents you can find the creation date of the VM, and it's orginal VMDK.

But the events are kept for max 1 year, and even less if you configured them that way.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

LucD
Leadership
Leadership

You could try something like this.

Note that I tested this in vSphere 6.5, not sure if older vSphere versions have that same info in the events.

$start = (Get-Date).AddMonths(-6)

$events = Get-VIEvent -Start $start -MaxSamples ([int]::MaxValue) |

    where{$_ -is [VMware.Vim.VmReconfiguredEvent] -and $_.ConfigChanges.Added.Count -ne 0}

foreach($event in $events){

    $event.ConfigSpec.DeviceChange |

    where{$_.Operation -eq 'add' -and $_.Device -is [VMware.Vim.VirtualDisk]} |

    Select @{N='VM';E={$event.Vm.Name}},

        @{N='DateTime';E={$event.CreatedTime}},

        @{N='CapacityGB';E={[math]::Round($_.Device.CapacityInKB/1MB,0)}},

        @{N='Thin';E={$_.Device.Backing.ThinProvisioned}},

        @{N='Filename';E={

            $script:ds = Get-View -Id $_.Device.Backing.Datastore -Property Name,Info.Url

            $_.Device.Backing.Filename.Replace($script:ds.Info.Url,"[$($script:ds.Name)] ")}}

}

    


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

virtubhuvan
Contributor
Contributor

Thanks for the script.

Would there be a better option finding the created date of the disk?

Querying of events takes hell lot of time to fetch the event data even for a month. Sometimes, the query gets terminated due to some unknown reasons.

Reply
0 Kudos
LucD
Leadership
Leadership

Not that I know off.

And yes, there is currently a known issue with retrieving events from vCenter.

That is being looked at, but no clue when it will be fixed. Smiley Sad


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos