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
You could do something like this
$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
You could do something like this
$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
How to get specific files using this scripts, this script returns all datastore files, I want to get only vmware.log file?
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
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.
That is quite an entirely different question
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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.
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