VMware Cloud Community
vmk2014
Expert
Expert
Jump to solution

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

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
vmk2014
Expert
Expert
Jump to solution

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

View solution in original post

0 Kudos
11 Replies
LucD
Leadership
Leadership
Jump to solution

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
vmk2014
Expert
Expert
Jump to solution

LucD,

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

thanks

vmk

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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
vmk2014
Expert
Expert
Jump to solution

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
LucD
Leadership
Leadership
Jump to solution

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
vmk2014
Expert
Expert
Jump to solution

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
LucD
Leadership
Leadership
Jump to solution

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
vmk2014
Expert
Expert
Jump to solution

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
LucD
Leadership
Leadership
Jump to solution

You dropped the last line that contains PowerState


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

0 Kudos
vmk2014
Expert
Expert
Jump to solution

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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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