VMware Cloud Community
ricky73
Hot Shot
Hot Shot
Jump to solution

vCPU number which are used in cluster environment

In cluster environment (ESX 5.5  U3) can I create report to get the number of all vCPU which I used to configured all VM, independently of VM is power on/off and number of hosts ESXi? I'd like to trace how many vCPU I already configured against those ones which, overall, all hosts have.

0 Kudos
1 Solution

Accepted Solutions
LikeABrandit
Enthusiast
Enthusiast
Jump to solution

As for which version of PowerCLI to use, you should be fine using 6.5 based on the interop matrix: VMware Product Interoperability Matrixes

If you're looking to modify the code yourself, here's the documentation for PowerCLI, it's really powerful and if you have the free time I'd definitely recommend diving in: VMware PowerCLI Documentation

Something like what Arjun recommended should work, but I think the host data you're looking for was missing and it may be difficult to follow what's happening if you're just starting with PowerCLI. Since it sounds like you may be looking for something to help you start making or customizing your own scripts, here's something I threw together in an attempt to make it easy enough to follow:

$VIServer = "vCenterName"

$vmLocation = "Cluster/Datacenter"

$hostArr = @()

$vmArr = @()

If (!(Get-Module | Where {$_.Name -eq "VMware.VimAutomation.Core"})) {

    Import-Module "VMware.VimAutomation.Core" -ErrorAction SilentlyContinue

}

Connect-VIServer $VIServer

ForEach ($vmHost in (Get-VMHost -Location $vmLocation)) {

  $vmHost = $vmHost | Select Name,ProcessorType,NumCpu,Model

  $hostArr += $vmHost

  ForEach ($vm in (Get-VM -Location $vmHost)) {

  $vm = Get-VM -Name $VMName | Select Name,PowerState,NumCpu

  $vmArr += $VM

  }

}

To help with following what's happening: Up top, the variables are being used to define what vCenter we connect to, what location we pull VMs from on that vCenter. $vmArr/$hostArr = @() is just being used to initialize our array variables. Next we're checking for/adding the module for PowerCLI. After that we connect to the vCenter (defined by the $VIServer variable). Finally, we loop through the hosts then VMs we want, grabbing info from each, then tossing that info into the arrays.

Basically, just adjust those 3 variables at the top as needed, and this will get you two arrays with the data you're looking for. The question is, what do you want to do with that data once you have it? I'd suggest determining what you want to get out of the info, and working from here to manipulate this code to give you what you need to see.

So you can either manipulate the data further, or export it as is. Since it's in two arrays, that's two exports. If you'd like a couple csv files for example, this would work (of course, adjust the location it's exporting to as needed):

$vmArr | Export-Csv -NoTypeInformation "C:\Users\username\Desktop\vmCpu.csv"

$hostArr | Export-Csv -NoTypeInformation "C:\Users\username\Desktop\hostCpu.csv"

Finally, we can go further, such as setting this up to e-mail these CSV files out, or put them on a network share, overwriting each time, so you have a location with up to date data on each script run. We could then save the script and make it a scheduled task on the machine with PowerCLI, so you could have this run on a regular basis.

~LikeABrandit

View solution in original post

0 Kudos
10 Replies
ArjunDooti
Enthusiast
Enthusiast
Jump to solution

Hi Ricky,

Get-VM |Where {$_.PowerState -eq PoweredOn} |Sort Name |Select Name, NumCPU, @{N=OSHAL;E={(Get-WmiObject -ComputerName $_.Name-Query SELECT * FROM Win32_PnPEntity where ClassGuid = ‘{4D36E966-E325-11CE-BFC1-08002BE10318}’ |Select Name).Name}}, @{N=OperatingSystem;E={(Get-WmiObject -ComputerName $_ -Class Win32_OperatingSystem |Select Caption).Caption}}, @{N=ServicePack;E={(Get-WmiObject -ComputerName $_ -Class Win32_OperatingSystem |Select CSDVersion).CSDVersion}}



You can change PoweredOn“ to "PowerOff" to get the list for powered off VM's




Thanks & Regards

Arjun dooti

ricky73
Hot Shot
Hot Shot
Jump to solution

What language is this one? What environment I can run this command Get-vm ?!?

0 Kudos
MBrownWFP
Enthusiast
Enthusiast
Jump to solution

If I'm understanding your requirement properly you can accomplish this from the Web Client GUI as well.

In vSphere Web Client select the Cluster > Related Objects > Virtual Machines. Right-click one of the column headers and select "Show/Hide Columns" and make sure "CPUs" is selected (as well as any other data you require). Now the Virtual Machines view will have a column showing the vCPU count for each VM. Power State is included in this view by default.

At the bottom-right of the Virtual Machines there is an icon that looks like a page with an arrow in it. Click the drop-down next to this and select "Copy All", then paste the result into Excel or similar application. Now you have an edit-able list of all VMs in the cluster which includes vCPU count and Power State.

Hope that helps.

Matt

ricky73
Hot Shot
Hot Shot
Jump to solution

Ok but I have to create this report monthly so it's necessary to get often  this data

0 Kudos
MBrownWFP
Enthusiast
Enthusiast
Jump to solution

The method I mentioned takes 2 minutes to complete.

You could also try a tool called RVTools. It is a free application that connects to your vCenter server and automatically gathers inventory data that is exportable to Excel.

Matt

0 Kudos
ricky73
Hot Shot
Hot Shot
Jump to solution

This job is executed by vSphere CLI ?

0 Kudos
ArjunDooti
Enthusiast
Enthusiast
Jump to solution

You can run above script using VMware power cli.

Before executing above script. connect to vCenter using below command

Connect-VIServer <vCentre Name>  -User <User Name> -Password "<password>"

Links

Installing PowerCLI in vSphere - YouTube

Thanks & Regards

Arjun Dooti

0 Kudos
ricky73
Hot Shot
Hot Shot
Jump to solution

Ok, I have vCenter 6 but ESXi 5.5 U3 on hosts so what power CLI version do you suggest to install?

0 Kudos
ricky73
Hot Shot
Hot Shot
Jump to solution

Where can I find documents about these objects so that I can to improve this query?

0 Kudos
LikeABrandit
Enthusiast
Enthusiast
Jump to solution

As for which version of PowerCLI to use, you should be fine using 6.5 based on the interop matrix: VMware Product Interoperability Matrixes

If you're looking to modify the code yourself, here's the documentation for PowerCLI, it's really powerful and if you have the free time I'd definitely recommend diving in: VMware PowerCLI Documentation

Something like what Arjun recommended should work, but I think the host data you're looking for was missing and it may be difficult to follow what's happening if you're just starting with PowerCLI. Since it sounds like you may be looking for something to help you start making or customizing your own scripts, here's something I threw together in an attempt to make it easy enough to follow:

$VIServer = "vCenterName"

$vmLocation = "Cluster/Datacenter"

$hostArr = @()

$vmArr = @()

If (!(Get-Module | Where {$_.Name -eq "VMware.VimAutomation.Core"})) {

    Import-Module "VMware.VimAutomation.Core" -ErrorAction SilentlyContinue

}

Connect-VIServer $VIServer

ForEach ($vmHost in (Get-VMHost -Location $vmLocation)) {

  $vmHost = $vmHost | Select Name,ProcessorType,NumCpu,Model

  $hostArr += $vmHost

  ForEach ($vm in (Get-VM -Location $vmHost)) {

  $vm = Get-VM -Name $VMName | Select Name,PowerState,NumCpu

  $vmArr += $VM

  }

}

To help with following what's happening: Up top, the variables are being used to define what vCenter we connect to, what location we pull VMs from on that vCenter. $vmArr/$hostArr = @() is just being used to initialize our array variables. Next we're checking for/adding the module for PowerCLI. After that we connect to the vCenter (defined by the $VIServer variable). Finally, we loop through the hosts then VMs we want, grabbing info from each, then tossing that info into the arrays.

Basically, just adjust those 3 variables at the top as needed, and this will get you two arrays with the data you're looking for. The question is, what do you want to do with that data once you have it? I'd suggest determining what you want to get out of the info, and working from here to manipulate this code to give you what you need to see.

So you can either manipulate the data further, or export it as is. Since it's in two arrays, that's two exports. If you'd like a couple csv files for example, this would work (of course, adjust the location it's exporting to as needed):

$vmArr | Export-Csv -NoTypeInformation "C:\Users\username\Desktop\vmCpu.csv"

$hostArr | Export-Csv -NoTypeInformation "C:\Users\username\Desktop\hostCpu.csv"

Finally, we can go further, such as setting this up to e-mail these CSV files out, or put them on a network share, overwriting each time, so you have a location with up to date data on each script run. We could then save the script and make it a scheduled task on the machine with PowerCLI, so you could have this run on a regular basis.

~LikeABrandit

0 Kudos