VMware Cloud Community
fborges555
Enthusiast
Enthusiast
Jump to solution

VM last Modified date

HI gurus

I have a old datastore that has a bunch of file in it, some of this file left behind are  no longer related to the vm , so I would like to run a PSCli script if possible that will go on this datastore and get the vmdk last modified date, is this possible ??

thanks a bunch gurus

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You could do something like this

$dsName = 'datastore'

$ds = Get-Datastore -Name $dsName

New-PSDrive -Location $ds -Name DS -PSProvider VimDatastore -Root '\' | Out-Null

Get-ChildItem -Path "DS:" -Recurse | select -Property DatastoreFullPath,LastWriteTime

Remove-PSDrive -Name DS -Confirm:$false


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

View solution in original post

0 Kudos
7 Replies
LucD
Leadership
Leadership
Jump to solution

You could do something like this

$dsName = 'datastore'

$ds = Get-Datastore -Name $dsName

New-PSDrive -Location $ds -Name DS -PSProvider VimDatastore -Root '\' | Out-Null

Get-ChildItem -Path "DS:" -Recurse | select -Property DatastoreFullPath,LastWriteTime

Remove-PSDrive -Name DS -Confirm:$false


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

0 Kudos
zeejaved2023
Contributor
Contributor
Jump to solution

How to get specific files using this scripts, this script returns all datastore files, I want to get only vmware.log file?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You can use the Filter parameter

Get-ChildItem -Path "DS:" -Filter "vmware.log" -Recurse | select -Property DatastoreFullPath,LastWriteTime

And you can use wildcards (* or ?) in the Filter

Get-ChildItem -Path "DS:" -Filter "vmware*.log" -Recurse | select -Property DatastoreFullPath,LastWriteTime

or

Get-ChildItem -Path "DS:" -Filter "vmware-?.log" -Recurse | select -Property DatastoreFullPath,LastWriteTime

 


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

zeejaved2023
Contributor
Contributor
Jump to solution

Thank you for replying, successfully getting the required result. 

I want to get the VM name also with this last modified date time but it gets datastore folder name and not getting VM actual name that is showing vcenter front page.

Please help me out to get VMs actual name and details such as specs with this get-childitem. or any way to use Get-VM in this above mentioned script to get all details of Get-VM and this current result and export in CSV file respectively VM name and vmware.log last modified date. 

Thank you. 

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That is quite an entirely different question


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

0 Kudos
zeejaved2023
Contributor
Contributor
Jump to solution

I am asking about this script which you gave and solved the problem. I want to get VM name also with that last modified data fetching from the datastore I also want that VM actual full name showing on vcenter using Get-VM so how can we use Get-VM within this script the above mentioned script. 

 

0 Kudos
LucD
Leadership
Leadership
Jump to solution

No need to do a Get-VM.

$dsName = 'datastore'

$ds = Get-Datastore -Name $dsName
New-PSDrive -Location $ds -Name DS -PSProvider VimDatastore -Root '\' | Out-Null
Get-ChildItem -Path "DS:" -Filter 'vmware.log' -Recurse |
Select-Object @{N='VM';E={$_.FolderPath.Split(' ')[1]}},DatastoreFullPath,LastWriteTime
Remove-PSDrive -Name DS -Confirm:$false


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

0 Kudos