ESXi

 View Only
  • 1.  vCPU number which are used in cluster environment

    Posted Jan 12, 2017 06:50 AM

    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.



  • 2.  RE: vCPU number which are used in cluster environment

    Posted Jan 12, 2017 06:52 PM

    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



  • 3.  RE: vCPU number which are used in cluster environment

    Posted Jan 12, 2017 07:34 PM

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



  • 4.  RE: vCPU number which are used in cluster environment

    Posted Jan 12, 2017 08:01 PM

    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



  • 5.  RE: vCPU number which are used in cluster environment

    Posted Jan 12, 2017 08:08 PM

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



  • 6.  RE: vCPU number which are used in cluster environment

    Posted Jan 12, 2017 09:10 PM

    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



  • 7.  RE: vCPU number which are used in cluster environment

    Posted Jan 13, 2017 04:22 AM

    This job is executed by vSphere CLI ?



  • 8.  RE: vCPU number which are used in cluster environment

    Posted Jan 19, 2017 11:50 AM

    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



  • 9.  RE: vCPU number which are used in cluster environment

    Posted Jan 22, 2017 08:06 AM

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



  • 10.  RE: vCPU number which are used in cluster environment

    Posted Jan 22, 2017 08:13 AM

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



  • 11.  RE: vCPU number which are used in cluster environment
    Best Answer

    Posted Jan 22, 2017 05:22 PM

    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