VMware Cloud Community
fborges555
Enthusiast
Enthusiast
Jump to solution

Find File folder for VM in all datastores

HI gurus

I am looking for a PSCLI script that will go on all datastores in a cluster  and look for a particular VM folder.

Is this possible

Thanks

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

My bad, that was from my test run.

I corrected the code above.


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

View solution in original post

Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

Yes, you could do something like this

$clusterName = 'cluster'

$folderName = 'folder'


Get-Cluster -Name $clusterName | Get-Datastore |

ForEach-Object -Process {

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

    Get-ChildItem -Path DS: -Filter $folderName -Recurse |

    Select Name,DatastoreFullPath

    Remove-PSDrive -Name DS -Confirm:$false

}


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

Reply
0 Kudos
fborges555
Enthusiast
Enthusiast
Jump to solution

L.

As always crazy good, thanks a bunch for the script, is there a way that get-datastore gets all  Datastore instead of chaging vsandatastore for every inquiry? or get like a wild(*) in folder ?

if not possible its cool also as well.

Thanks again

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

My bad, that was from my test run.

I corrected the code above.


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

Reply
0 Kudos
fborges555
Enthusiast
Enthusiast
Jump to solution

as always worked like a charm!!!!!!

Thanks

Reply
0 Kudos