VMware Cloud Community
amitkadam10
Contributor
Contributor

Looking for a Power CLI query /script which will dump all the contents of a datastore as we get to see when we browse it .

Hi All,

I am new to vmware and a beginner on power cli.I am posting a question for the first time 🙂

I am in need to gather information about all the folder in a datastore .

What i exactly need is a browse datastore output in a excel , irrespective if it a vm added in inventory / a stale folder or a ISO folder .

Please help me ,. i have gone through a lot a blogs and found one thing which is close to what i need .

Link :Get datastore folders with PowerCLI

The output is as below , what it does is it lists the name of folder and the files in the foreground mode. I want it in a excel which i sent forward to the users.

Also i have been looking for some output formatting the length i believe is the size of file can it be in MB and the Name why does it come up as "Win2K8R2-ADDM-PRO..." rather then the complete name ?

Is there a way to format it .

Datastore path: [Customer_31]

         LastWriteTime            Type       Length Name

         -------------            ----       ------ ----

   1/18/2017   3:03 PM          Folder              Win2K8R2-ADDM-PROBE

Datastore path: [Customer_31] Win2K8R2-ADDM-PROBE

         LastWriteTime            Type       Length Name

         -------------            ----       ------ ----

   1/18/2017   3:03 PM    VmConfigFile         3756 Win2K8R2-ADDM-PRO...

   1/16/2017   3:22 PM     VmNvramFile         8684 Win2K8R2-ADDM-PRO...

   1/16/2017   3:22 PM       VmLogFile       600597 vmware.log

   1/16/2017   3:22 PM            File 214748364800 Win2K8R2-ADDM-PRO...

   1/16/2017   3:46 PM            File          274 Win2K8R2-ADDM-PRO...

   1/16/2017   3:22 PM            File            0 Win2K8R2-ADDM-PRO...

0 Kudos
6 Replies
LucD
Leadership
Leadership

Try like this.

It uses the vimdatastore provider.

$dsName = 'DS1'

$ds = Get-Datastore -Name $dsName

$dc = Get-VMHost -Datastore $ds | Get-Datacenter

Get-ChildItem -Path "vmstore:\$($dc.Name)\$($ds.Name)" -Recurse |

Select Name,DatastoreFullPath,ItemType,LastWriteTime,Length |

Export-Csv dsreport.csv -NoTypeInformation -UseCulture


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

0 Kudos
amitkadam10
Contributor
Contributor

Hi Luke ,

It worked as expected , further i did some filters in excel as needed .

Request : Where can i find workshopd for powercli begineers

0 Kudos
LucD
Leadership
Leadership

Not sure what you mean with workshop.
Do you mean a course?


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

0 Kudos
amitkadam10
Contributor
Contributor

Hi Luc ,

Yes i meant where can i find a online classroom or a lab to build my knowledge

0 Kudos
LucD
Leadership
Leadership

Have a look at HOL-1721-SDC-6 - vSphere Automation with PowerCLI


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

0 Kudos
amitkadam10
Contributor
Contributor

Thank Luke i will take a look .

0 Kudos