VMware Cloud Community
Mallik7
Enthusiast
Enthusiast

In need of a PowerCLI script

I'm in need of a powercli script to get the ESXi host model, CPU, Memory, CPU model. I've about 300 VMs in my list and those are in different vCenters.

Would like to input them in a file and then script should be able to provide the above asked information.

Script should be able to check, currently on which ESXi host each VM residing on and get the ESXi host list and its required information (in a tabular format) like below:

VM name, ESXi host name, Host Model, CPU, Memory, ESXi host CPU model

can some one help here please.  TIA

4 Replies
T180985
Expert
Expert

get-VM | Select Name,

@{N="Host";E={$_ | Get-VMhost | select -ExpandProperty Name}},

@{N="Model";E={$_ | Get-VMhost | select -ExpandProperty Model}},

@{N="CPU";E={$_ | Get-VMhost | select -ExpandProperty ProcessorType}},

@{N="NumCPU";E={$_ | Get-VMhost | select -ExpandProperty NumCpu}},

@{N="MemGB";E={$_ | Get-VMhost| select -ExpandProperty MemoryTotalGB}} | FT

Please mark helpful or correct if my answer resolved your issue. How to post effectively on VMTN https://communities.vmware.com/people/daphnissov/blog/2018/12/05/how-to-ask-for-help-on-tech-forums
Reply
0 Kudos
Mallik7
Enthusiast
Enthusiast

thanks, does it take the VM names from a file ?

Reply
0 Kudos
T180985
Expert
Expert

$vmList = Get-Content C:\temp\inputFile.txt

get-VM $vmName | Select Name,

@{N="Host";E={$_ | Get-VMhost | select -ExpandProperty Name}},

@{N="Model";E={$_ | Get-VMhost | select -ExpandProperty Model}},

@{N="CPU";E={$_ | Get-VMhost | select -ExpandProperty ProcessorType}},

@{N="NumCPU";E={$_ | Get-VMhost | select -ExpandProperty NumCpu}},

@{N="MemGB";E={$_ | Get-VMhost| select -ExpandProperty MemoryTotalGB}} | FT

get-vm accepts an array of one or more names

Please mark helpful or correct if my answer resolved your issue. How to post effectively on VMTN https://communities.vmware.com/people/daphnissov/blog/2018/12/05/how-to-ask-for-help-on-tech-forums
LucD
Leadership
Leadership

As an alternative, and without the many calls to Get-VMHost, you could do

Get-VM -Name (Get-Content -Path .\vmnames.txt) |

Select Name,

    @{N="VMHost";E={$_.VMhost.Name}},

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

    @{N="CPU";E={$_.VMhost.ProcessorType}},

    @{N="NumCPU";E={$_.VMhost.NumCpu}},

    @{N="MemGB";E={$_.VMhost.MemoryTotalGB}} |

Format-Table -AutoSize


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