Pages: [1] 2
Print
Author Topic: get the socket/core info for each vmware host  (Read 2291 times)
esarakaitis
Administrator
Full Member
*****
Posts: 241


8223109 sack57@hotmail.com littleking57 rootinfortwayne
View Profile WWW Email
« on: February 05, 2009, 10:41:55 AM »

Code:
Get-VMHost | %{Get-View $_.ID} | %{
  $name = $_.name
  $esx = "" | select NumCpuPackages, NumCpuCores, Hz, Memory
  $esx.NumCpuPackages = $_.Hardware.CpuInfo.NumCpuPackages
  $esx.NumCpuCores = $_.Hardware.CpuInfo.NumCpuCores
  $esx | select-object @{Name = "Name"; Expression = {$name}}, @{Name = "Sockets"; Expression = {$esx.NumCpuPackages}}, @{Name = "Cores"; Expression = {$esx.NumCpuCores}}
  }
Logged
X505
Newbie
*
Posts: 3



View Profile WWW
« Reply #1 on: February 09, 2009, 02:14:13 PM »

Hi esarakaitis,
Thanks a lot for this little code sample  Cool

In order to check vmotion Capabilities between my hosts, i do some changes from your script. It might help someone :

Code:
$Col = @()    # Prepare output collection
Get-VMHost | %{Get-View $_.ID} | %{
  $esx = "" | select name, NumCpuPackages, NumCpuCores, CpuMhz, CpuModel
  $esx.name = $_.name
  $esx.NumCpuPackages = $_.Hardware.CpuInfo.NumCpuPackages
  $esx.NumCpuCores = $_.Hardware.CpuInfo.NumCpuCores
  $esx.CpuMhz = $_.Summary.Hardware.CpuMhz
  $esx.CpuModel = $_.Summary.Hardware.CpuModel
  $esx | select-object (
  @{Name = "Name"; Expression = {$esx.name}},
  @{Name = "Sockets"; Expression = {$esx.NumCpuPackages}},
  @{Name = "Cores"; Expression = {$esx.NumCpuCores}},
  @{Name = "MHz"; Expression = {$esx.CpuMhz}},
  @{Name = "Model"; Expression = {$esx.CpuModel}}
  )
  $Col += $esx   # Add output to collection
  }
  $Col | Export-Csv ./cpuinfo.csv -NoTypeInformation   # Export output to csv

Edit : add csv export

« Last Edit: February 09, 2009, 02:43:06 PM by X505 » Logged

esarakaitis
Administrator
Full Member
*****
Posts: 241


8223109 sack57@hotmail.com littleking57 rootinfortwayne
View Profile WWW Email
« Reply #2 on: February 10, 2009, 07:25:29 AM »

very nice! and welcome aboard!
Logged
X505
Newbie
*
Posts: 3



View Profile WWW
« Reply #3 on: February 10, 2009, 09:36:49 AM »

very nice! and welcome aboard!

Thanks Smiley
Logged

dma0211
Newbie
*
Posts: 15


View Profile
« Reply #4 on: June 23, 2009, 01:54:48 PM »

Why not do it for all the hosts in VC. Here is just the socket count.


Code:
$vc = Read-Host "Enter VC server name"
Connect-VIServer "$VC"

$report = @()
get-vmhost | Sort Name -Descending | % {
  $vmh = Get-View $_.ID
    $vmhs = "" | Select-Object VMHName, Summary
    $vmhs.VMHName = $vmh.Name
$vmhs.Summary = $vmh.Summary.Hardware.NumCpuPkgs
$report += $vmhs
}
$report | Export-Csv "C:\vmh_hostsummary.csv" -NoTypeInformation
Logged
esarakaitis
Administrator
Full Member
*****
Posts: 241


8223109 sack57@hotmail.com littleking57 rootinfortwayne
View Profile WWW Email
« Reply #5 on: June 24, 2009, 06:17:12 AM »

what do you mean, the initial script gets the information for each host
Logged
dma0211
Newbie
*
Posts: 15


View Profile
« Reply #6 on: June 24, 2009, 09:12:05 AM »

Sorry about that, I did not see a VC connection and thought you were connecting to a single host.
Logged
esarakaitis
Administrator
Full Member
*****
Posts: 241


8223109 sack57@hotmail.com littleking57 rootinfortwayne
View Profile WWW Email
« Reply #7 on: June 24, 2009, 01:22:05 PM »

i dont specify vc connection in any of my scripts, as I'm assuming that your either already connected or planning on connecting Smiley
Logged
dma0211
Newbie
*
Posts: 15


View Profile
« Reply #8 on: June 24, 2009, 03:39:47 PM »

Seems like anytime I try that, it always backfires. Good to know. This is a great resource.
Logged
esarakaitis
Administrator
Full Member
*****
Posts: 241


8223109 sack57@hotmail.com littleking57 rootinfortwayne
View Profile WWW Email
« Reply #9 on: June 25, 2009, 07:26:46 AM »

Smiley no problem!
Logged
PJ
Newbie
*
Posts: 3


View Profile
« Reply #10 on: March 08, 2010, 01:25:32 PM »

Hi Eric,
 
I am newbie in both vmware and scripting.
 
Please help me in your script below. I want to run your script to get an information of vmware socket in our environment.
 
1. Is your script in power shell?
2. how do i connect to vCenter and get the output to a excel.
3. Can you please provide me the complete code.
 
Thanks in advance for your help.
PJ
Logged
esarakaitis
Administrator
Full Member
*****
Posts: 241


8223109 sack57@hotmail.com littleking57 rootinfortwayne
View Profile WWW Email
« Reply #11 on: March 08, 2010, 01:29:37 PM »

yes its in powershell, this is the powershell section of the forum.
to connect to vCenter type: connect-viserver "vcenter name"

Code:
$myCol = @()
ForEach ($Cluster in Get-Cluster)
    {
        ForEach ($vmhost in ($cluster | Get-VMHost))
        {
            $VMView = $VMhost | Get-View
                        $VMSummary = ?? | Select HostName, ClusterName, MemorySizeGB, CPUSockets, CPUCores
                        $VMSummary.HostName = $VMhost.Name
                        $VMSummary.ClusterName = $Cluster.Name
                        $VMSummary.MemorySizeGB = $VMview.hardware.memorysize / 1024Mb
                        $VMSummary.CPUSockets = $VMview.hardware.cpuinfo.numCpuPackages
                        $VMSummary.CPUCores = $VMview.hardware.cpuinfo.numCpuCores
                        $myCol += $VMSummary
                    }
            }
$myCol #| export-csv c:\1.csv #| out-gridview

just comment out the export function you want.
Logged
PJ
Newbie
*
Posts: 3


View Profile
« Reply #12 on: March 08, 2010, 01:55:51 PM »

thanks for your quick response.

can i run this script remotely from my machine or run it the vCenter.
if i can run it from my machine do I need to add some steps in the script to authenticate the vCenter.
Logged
esarakaitis
Administrator
Full Member
*****
Posts: 241


8223109 sack57@hotmail.com littleking57 rootinfortwayne
View Profile WWW Email
« Reply #13 on: March 08, 2010, 03:11:39 PM »

either way, i explained in the previous post on how to authenicate to the vcenter

have you read the readme that came with PowerCLI?
Logged
PJ
Newbie
*
Posts: 3


View Profile
« Reply #14 on: March 09, 2010, 02:16:38 PM »

Thanks a lot! It worked.
Logged
Pages: [1] 2
Print
Jump to: