Expert
Expert

VM's list running on the specific Hosts in a cluster

Jump to solution

Hi All,

Can we pull the list of VM's running on specific host e.g. C:\temp\hostname.txt.  from power cli script ?

Want to include cluster name also and power state of VM's

thanks

vmk

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
Expert
Expert

Oops you are right. Now, i can see the report without any flaw.

View solution in original post

0 Kudos
11 Replies
Leadership
Leadership

Try something like this

Get-VMHost -Name (Get-Content -Path C:\temp\hostname.txt) -PipelineVariable esx |

Get-VM |

Select @{N='Cluster';E={(Get-Cluster -VMHost $esx).Name}},

   @{N='VMHost';E={$esx.Name}},

   @{N='VM';E={$_.Name}}


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

0 Kudos
Expert
Expert

LucD,

Can we add the VM's state whether it's powered on off?

thanks

vmk

0 Kudos
Leadership
Leadership

Sure

Get-VMHost -Name (Get-Content -Path C:\temp\hostname.txt) -PipelineVariable esx |

   Get-VM |

  Select @{N = 'Cluster'; E = {(Get-Cluster -VMHost $esx).Name}},

@{N = 'VMHost'; E = {$esx.Name}},

@{N = 'VM'; E = {$_.Name}},

PowerState


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

0 Kudos
Expert
Expert

LucD,

Sorry for the delayed reply.  I missed out sharing that the script unable to read hostname in  FQDN. Can you add that too?

0 Kudos
Leadership
Leadership

Try like this

Get-VMHost -Name (Get-Content -Path C:\temp\hostname.txt) -PipelineVariable esx |

Get-VM |

Select @{N = 'Cluster'; E = {(Get-Cluster -VMHost $esx).Name}},

   @{N = 'VMHost'; E = {$esx.Name}},

   @{N = 'VMHost FQDN';E={"$($esx.NetworkInfo.HostName).$($esx.NetworkInfo.DomainName)"}},

   @{N = 'VM'; E = {$_.Name}},

  PowerState


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

0 Kudos
Expert
Expert

LucD,

the output generated without any error but VM's state is not reflecting whether it's powered off or on

ClusterVMHostVMHost FQDNVM

thanks

vmk

0 Kudos
Leadership
Leadership

Is that your output header?

There is no PowerState property. Or is that because it doesn't fit on your screen? Try to pipe the output to Format-List.
Can you show me the code you are using? It looks like the last line from my code is missing.


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

0 Kudos
Expert
Expert

Get-VMHost -Name (Get-Content -Path C:\temp\hostname.txt) -PipelineVariable esx |

Get-VM | Select @{N = 'Cluster'; E = {(Get-Cluster -VMHost $esx).Name}},

   @{N = 'VMHost'; E = {$esx.Name}},

   @{N = 'VMHost FQDN';E={"$($esx.NetworkInfo.HostName).$($esx.NetworkInfo.DomainName)"}},

   @{N = 'VM'; E = {$_.Name}} |

Export-Csv -Path C:\Temp\VM-lists_runningonHost.csv -NoTypeInformation -UseCulture

0 Kudos
Leadership
Leadership

You dropped the last line that contains PowerState


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

0 Kudos
Expert
Expert

Oops you are right. Now, i can see the report without any flaw.

View solution in original post

0 Kudos
Leadership
Leadership

Was it the intention that you marked your own reply as the correct answer?


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

0 Kudos