VMware Cloud Community
neil_armstrong7
Contributor
Contributor
Jump to solution

Simple .CSV output required... but having issues

Hi guys,

I am trying to create a simple report that contains

Virtual Centre Name - ESX Host - Guest Name - Power State - VM Tools installed

I don't think I can get the VC name but I can just inject that manually, but do need all the others.

Can you help

Reply
0 Kudos
1 Solution

Accepted Solutions
halr9000
Commander
Commander
Jump to solution

different technique:

Get-VMHost | select {$_.Name}, { (Get-VM -Location $_).Name }, { (Get-VM -Location $_).PowerState }

Hal Rottenberg

Co-Host, PowerScripting Podcast (http://powerscripting.net)

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000

View solution in original post

Reply
0 Kudos
5 Replies
LucD
Leadership
Leadership
Jump to solution

The following should put you on the way.

Get-VMHost | %{$esx = $_; Get-VM -Location $_} | `
    %{$vm = Get-View $_.ID; 
	  Write-Output $esx.name $_.name $_.powerstate $vm.config.tools.toolsVersion}

For the tools it shows the installed version (0 means not installed).

This can be converted to a Boolean (true/false) with an IF statement.


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

neil_armstrong7
Contributor
Contributor
Jump to solution

Close..

I am using Get-VMHost | %{$esx = $_; Get-VM -Location $_} | %{Write-Output $esx.name $_.name $_.powerstate}

but the ouput I am getting is :

vm000020

CEOV00010

PoweredOn

When I need : vm000020, CEOV00010, PoweredOn

Can anyone else help

Reply
0 Kudos
halr9000
Commander
Commander
Jump to solution

different technique:

Get-VMHost | select {$_.Name}, { (Get-VM -Location $_).Name }, { (Get-VM -Location $_).PowerState }

Hal Rottenberg

Co-Host, PowerScripting Podcast (http://powerscripting.net)

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
Reply
0 Kudos
neil_armstrong7
Contributor
Contributor
Jump to solution

Thank you for your help - just what I needed.

And I can follow the login in this one

Reply
0 Kudos
halr9000
Commander
Commander
Jump to solution

Read up on "calculated properties" in powershell with select-object and format-table. Powerful stuff. Note that you can make the column names pretty by putting a label in a hashtable.

$column1 = @{ Name = "column one"; Expression = { # code goes here } } # select-object uses Name key

$column1 = @{ Label = "column one"; Expression = { # code goes here } } # format-table uses Label key

(Don't ask me why they take two different keys for the same purpose. I call it a bug and logged it as such on the powershell connect website.)

Hal Rottenberg

Co-Host, PowerScripting Podcast (http://powerscripting.net)

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
Reply
0 Kudos