PowerCLI

 View Only
  • 1.  Get-Folder Datastore VM - New to powercli

    Posted Feb 03, 2017 06:06 PM

    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.



  • 2.  RE: Get-Folder Datastore VM - New to powercli

    Posted Feb 03, 2017 06:36 PM

    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







  • 3.  RE: Get-Folder Datastore VM - New to powercli

    Posted Feb 04, 2017 06:29 AM

    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)}}



  • 4.  RE: Get-Folder Datastore VM - New to powercli

    Posted Apr 30, 2021 10:13 AM

    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.