VMware Cloud Community
KimM
Contributor
Contributor
Jump to solution

Script to gather and calculate total number og sockets pr. cluster

Hi,

for licensing purposes I need to gather a report on host and socket information per host.

I want the report to include the following:
- Show host information per cluster (attached script).

- A headline with clustername per cluster

- The total number of sockets per cluster

I guess my problem is that I'm working in an array and I want to insert empty lines and headlines and my tries have not been successful so far. I'm not sure if I should convert to html and alter the layout that way. (hope not)

I'd appreciate any help...

/Kim

0 Kudos
1 Solution

Accepted Solutions
RvdNieuwendijk
Leadership
Leadership
Jump to solution

Hi Kim,

Welcome to the VMware Communities.

I have modified your script to include a header line per cluster with the name and the total number of sockets for the cluster:

$clusters = get-cluster | sort name
$vms = $null
if(test-path report.htm)
{
    remove-item report.htm
}

foreach ($cluster in $clusters){
    $report = @()
    $ClusterSockets = 0
    foreach ($ESXHost in ($cluster | Get-VMHost | Sort Name)){
        $row = "" | Select Name, Version, Build, ClusterName, Model, ProcessorType, Sockets, Cores, PNics 
        $row.name = $ESXHost.name
        $row.version = $ESXHost.version
        $row.build = $ESXHost.build
        $row.clustername = $cluster.name
        $row.model = $ESXHost.model
        $row.ProcessorType = $ESXHost.ProcessorType
        $row.sockets = ($ESXHost | Get-View).Hardware.CpuInfo.NumCpuPackages
        $ClusterSockets += $row.sockets
        $row.cores = ($ESXHost | Get-View).Hardware.CpuInfo.NumCpuCores
        $row.PNics = ($ESXHost | Get-View).Config.Network.Pnic.Count
        $report += $row
    } # End foreach host
    "<h1>$($Cluster.Name), Number of sockets: $ClusterSockets</h1>" | Out-File report.htm -append
    $report  | ConvertTo-HTML | Out-File report.htm -append
} # End foreach cluster

.\report.htm

Regards, Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition

View solution in original post

0 Kudos
2 Replies
RvdNieuwendijk
Leadership
Leadership
Jump to solution

Hi Kim,

Welcome to the VMware Communities.

I have modified your script to include a header line per cluster with the name and the total number of sockets for the cluster:

$clusters = get-cluster | sort name
$vms = $null
if(test-path report.htm)
{
    remove-item report.htm
}

foreach ($cluster in $clusters){
    $report = @()
    $ClusterSockets = 0
    foreach ($ESXHost in ($cluster | Get-VMHost | Sort Name)){
        $row = "" | Select Name, Version, Build, ClusterName, Model, ProcessorType, Sockets, Cores, PNics 
        $row.name = $ESXHost.name
        $row.version = $ESXHost.version
        $row.build = $ESXHost.build
        $row.clustername = $cluster.name
        $row.model = $ESXHost.model
        $row.ProcessorType = $ESXHost.ProcessorType
        $row.sockets = ($ESXHost | Get-View).Hardware.CpuInfo.NumCpuPackages
        $ClusterSockets += $row.sockets
        $row.cores = ($ESXHost | Get-View).Hardware.CpuInfo.NumCpuCores
        $row.PNics = ($ESXHost | Get-View).Config.Network.Pnic.Count
        $report += $row
    } # End foreach host
    "<h1>$($Cluster.Name), Number of sockets: $ClusterSockets</h1>" | Out-File report.htm -append
    $report  | ConvertTo-HTML | Out-File report.htm -append
} # End foreach cluster

.\report.htm

Regards, Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
KimM
Contributor
Contributor
Jump to solution

Thanks a lot, it's exactly what I need...

/Kim

0 Kudos