VMware Cloud Community
hugop
Hot Shot
Hot Shot
Jump to solution

List all powered on VMs and Host that it is running on

As subject.

Thanks!

Hugo

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

The @#!&* forum SW dropped the new-lines (again).

Try the attached script.


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

View solution in original post

0 Kudos
8 Replies
LucD
Leadership
Leadership
Jump to solution

Something like this ?

Get-VM | where {$_.PowerState –eq "Poweredon"} | %{write-host $_.name $_.host.name}


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

hugop
Hot Shot
Hot Shot
Jump to solution

How can I pipe it to csv file?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Something like.

$report = @()
Get-VM | where {$_.PowerState –eq "Poweredon"} | %{
  $row = "" | select VMname, HostName
  $row.VMName = $_.Name
  $row.HostName = $_.host.Name
  $report += $row
}
$report | Export-Csv "C:\report.csv" -noTypeInformation


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

0 Kudos
hugop
Hot Shot
Hot Shot
Jump to solution

error with @() Get-vm

PS C:\Program Files\VMware\Infrastructure\VIToolkitForWindows> $report = @() Get

-VM | where {$_.PowerState -eq "Poweredon"} | %{ $row = "" | select VMname, Host

Name $row.VMName = $_.Name $row.HostName = $_.host.Name $report += $row } $repor

t | Export-Csv "C:\report.csv" -noTypeInformation

Unexpected token 'Get-VM' in expression or statement.

At line:1 char:21

+ $report = @() Get-VM <<<< | where {$_.PowerState -eq "Poweredon"} | %{ $row

= "" | select VMname, HostName $row.VMName = $_.Name $row.HostName = $_.host.Na

me $report += $row } $report | Export-Csv "C:\report.csv" -noTypeInformation

PS C:\Program Files\VMware\Infrastructure\VIToolkitForWindows>

0 Kudos
LucD
Leadership
Leadership
Jump to solution

The @#!&* forum SW dropped the new-lines (again).

Try the attached script.


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

0 Kudos
hugopeeters
Hot Shot
Hot Shot
Jump to solution

I was a bit surprized to see myself asking this question.

Turns out I have a "doppelganger". Hello Hugo!

Check out my website for more example scripts: www.peetersonline.nl

Hugo Peeters

0 Kudos
hugopeeters
Hot Shot
Hot Shot
Jump to solution

I was a bit surprized to see myself asking this question.

Turns out I have a "doppelganger". Hello Hugo!

Check out my website for more example scripts: www.peetersonline.nl

Hugo Peeters

0 Kudos
hugop
Hot Shot
Hot Shot
Jump to solution

"Any resemblance to actual persons, living or dead, is purely coincidental"

Smiley Happy

Yup, just started playing around with the VI Toolkit.

0 Kudos