VMware Cloud Community
Mbogeholm
Contributor
Contributor
Jump to solution

VM Inventory with special requests

Hi

I'm struggeling with creating a PowerCli script to get a report looking like this:

VMName, NumCpu, MemoryMB, Number of Nics,Names of VMDK-files

Output could look like this

Name               NumCpu      MemoryMB        NICS          VMDK1                  VMDK2                 VMDK3

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

MyVM01           2                4096                  1               myvm01.vmdk         myvm01_1.vmdk

MyVM02           1                2048                  2               myvm02.vmdk

...

My VMnn          1                2048                  2               myvmnn.vmdk

I got the simple stuff in place, but need help with the more tricky ones...

get-vm | select-object Name, NumCpu, MemoryMB | Export-CSV c:\temp\special_vm_inventory.csv

I appreciate your help Smiley Happy

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try it like this

Get-VM | Select Name,NumCpu,MemoryMB,
    @{N="NICS";E={$_.NetworkAdapters.Count}},
    @{N="VMDK1";E={$_.HardDisks[0].FileName}},
    @{N="VMDK2";E={$_.HardDisks[1].FileName}},
    @{N="VMDK3";E={$_.HardDisks[2].FileName}} |
Export-Csv "C:\report.csv" -NoTypeInformation -UseCulture


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

View solution in original post

0 Kudos
3 Replies
LucD
Leadership
Leadership
Jump to solution

Try it like this

Get-VM | Select Name,NumCpu,MemoryMB,
    @{N="NICS";E={$_.NetworkAdapters.Count}},
    @{N="VMDK1";E={$_.HardDisks[0].FileName}},
    @{N="VMDK2";E={$_.HardDisks[1].FileName}},
    @{N="VMDK3";E={$_.HardDisks[2].FileName}} |
Export-Csv "C:\report.csv" -NoTypeInformation -UseCulture


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

0 Kudos
Mbogeholm
Contributor
Contributor
Jump to solution

Thank you very much LucD - it did the job just as it should! Smiley Happy

I'm very happy about it, and learned something too

A bonus question:

I have a hard time finding the documentation/reference of the classes/.Net objects, just like you use in the NIC-count and names of the disk files.

I Googled a lot but didn't quite find what I was looking for.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You can find the properties of each object in the online PowerCLI reference.

For example, the Get-VM cmdlet returns a VirtualMachine object.

On that page you see all the properties of that object, and you can drill down, like for example with the Harddisks property.

On each cmdlet reference page, you will find a link to the object it retruns.

See the Get-VM page.


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