VMware Cloud Community
jeffreywmcclain
Enthusiast
Enthusiast
Jump to solution

Get-InventoryPlus with VM id?

I need a script that exports a csv file listing all VMs, including their name, id, power state, yellow path, and blue path. I've taken LucD's Get-InventoryPlus function and attempted to bolt on additional functionality such as the PowerState, however I'm not sure how to add a column for vm ID. I would like the ID column because we have multiple VMs with the same name but in different folders, so name itself is not a unique enough field to use "get-VM". Would it be as simple as modifying the Get-View part of the script to the following, or is my syntax incorrect?

Get-View -ViewType VirtualMachine -Property Name, Parent, ID, Runtime.PowerState |

  Select Name,

    @{N = "ID"; E = {$_.ID}},

    @{N = 'BlueFolderPath'; E = {Get-ViBlueFolderPath -Item $_}},

    @{N = "PowerState"; E = {$_.Runtime.PowerState}}

Tags (1)
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

No problem, always happy to help :smileygrin:

Try the attached version, it only gets VMs


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

View solution in original post

4 Replies
LucD
Leadership
Leadership
Jump to solution

Try with the attached version.


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

jeffreywmcclain
Enthusiast
Enthusiast
Jump to solution

Thanks, I'll test this when I'm back at the office later this week!

Would it be possible to combine this approach with:

Get-View -ViewType VirtualMachine -Property Name, Parent, Runtime.PowerState |

  Select Name,

    @{N = 'BlueFolderPath'; E = {Get-ViBlueFolderPath -Item $_}},

    @{N = "PowerState"; E = {$_.Runtime.PowerState}}

To reiterate, I only need to export a csv file listing all VMs, specifically each VM's Name, ID, PowerState, Blue folder path, and Yellow folder path. I apologize if this is trivial, I'm still somewhat new to PowerCLI and I've already tried modifying your get-inventoryplus script in various ways, but I feel like with each variation I'm either losing a bit of the functionality I desire or I'm just not doing the query very efficiently (as I don't need to get all inventory objects, just the VMs and the specific properties I mentioned).

I understand if you don't want to spend more time assisting me, you've provided enough examples that I should be able to use/combine them and figure it out myself eventually. Regardless, thanks for everything, I really appreciate it!

0 Kudos
LucD
Leadership
Leadership
Jump to solution

No problem, always happy to help :smileygrin:

Try the attached version, it only gets VMs


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

jeffreywmcclain
Enthusiast
Enthusiast
Jump to solution

Thank you so much, once I get back in the office it should be trivial for me to use "get-vm" and the vm id field to populate the csv file with other vm properties like the powerstate.

I won't be able to test this till later this week, but I'm going to preemptively mark your response as the answer. Thanks again!

0 Kudos