VMware Cloud Community
vmCalgary
Enthusiast
Enthusiast

Get-Folder Datastore VM - New to powercli

pastedImage_0.png

The above is a datastore folder containing four datastores. I'd like to find out the VM names, power status, usageGB, and cluster of VM for all VMs using those four datastores. I'm struggling with using get-datastore, get-folder -type datastore, get-vm to get this information.

Get-Folder -name stc03-lab | get-datastore | get-vm gives me kind of what I want:

PowerCLI C:\> get-folder -name stc03-lab | get-datastore | get-vm -name mgt3.

Name                 PowerState Num CPUs MemoryGB

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

mgt3. PoweredOn  2        2.000

What I want is:

VM Name                Datastore                                PowerState                 

mgt3                         st037_nl                                   PoweredOn               

It would be really nice to add in provisioned and used resources (memory, cpu, and storage). I am new to powercli and would appreciate any help the community can offer.

0 Kudos
3 Replies
UmeshAhuja
Commander
Commander

Hi,

Try this

Get-VM |

Select Name,PowerState,

@{N="Datastore";E={[string]::Join(',',(Get-Datastore -Id $_.DatastoreIdList | Select -ExpandProperty Name))}},

@{N="UsedSpaceGB";E={[math]::Round($_.UsedSpaceGB,1)}},

@{N="ProvisionedSpaceGB";E={[math]::Round($_.ProvisionedSpaceGB,1)}},

@{N="Folder";E={$_.Folder.Name}} |

Export-Csv C:\report.csv -NoTypeInformation -UseCulture





Thanks n Regards
Umesh Ahuja

If your query resolved then please consider awarding points by correct or helpful marking.
0 Kudos
LucD
Leadership
Leadership

Try like this

It uses the PipelineVariable to have access to the Datastore object.

Note that the provisioned and used properties are the values over all datastores, provided the VM has files on multiple datastores.

If you want to see these values per datastore, the logic of the script will need to be changed

Get-Folder -Name stc03-lab | Get-Datastore -PipelineVariable ds | Get-VM |

Select Name,@{N='Datastore';E={$ds.Name}},PowerState,NumCpu,MemoryGB,

    @{N='ProvisionedSpaceGB';E={[math]::Round($_.ProvisionedSpaceGB,1)}},

    @{N='UsedSpaceGB';E={[math]::Round($_.UsedSpaceGB,1)}}


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

0 Kudos
2596060555
Contributor
Contributor

Hi LucD

Is it possible to obtain a report with the capacity and free space of each storage folder?

For examole  Foreach get-folder -type Datastore capacity,, free space ?

Please help me.

0 Kudos