VMware Cloud Community
suelai09
Contributor
Contributor
Jump to solution

PowerCLI- Get NumCoresPerSocket for multiple servers

Greetings,

I am very very new to scripting and i am given a task to get the number of cores per socket for multiple server.

Getting the number of CPUs isn't a problem with PowerCLI. However, i am having difficulty to get the number of cores per socket for multiple server.

In the script below, i am only able to obtain the number of CPU and number of cores per socket for 1 server.

$result = @()

$vms = Get-View -ViewType VirtualMachine -Filter @{"Name" = "UK2SAWN00229"}

foreach ($vm in $vms) {

    $obj = new-object psobject

    $obj | Add-Member -MemberType NoteProperty -Name name -Value $vm.Name

    $obj | Add-Member -MemberType NoteProperty -Name CPUSocket -Value $vm.config.hardware.NumCPU

    $obj | Add-Member -MemberType NoteProperty -Name Corepersocket -Value $vm.config.hardware.NumCoresPerSocket

    $result += $obj

}

$result | export-csv -path C:\cpu.txt

I wish to have something like - key in the multiple server name in notepad(not all the servers in VC) and able to get the result for the servers i want.

I tried to modified the script as below. I have given 2-3 servers in servers.txt, however, the script is not working for multiple servers. I

$result = @()

$vms = Get-View -ViewType VirtualMachine -Filter @{"Name" = Get-Content c:\STest\servers.txt}

foreach ($vm in $vms) {

    $obj = new-object psobject

    $obj | Add-Member -MemberType NoteProperty -Name name -Value $vm.Name

    $obj | Add-Member -MemberType NoteProperty -Name CPUSocket -Value $vm.config.hardware.NumCPU

    $obj | Add-Member -MemberType NoteProperty -Name Corepersocket -Value $vm.config.hardware.NumCoresPerSocket

    $result += $obj

}

$result | export-csv -path C:\STest\cpu.txt

Does anybody have any idea on how to get this done? Getting number of CPU and number cores per socket for multiple server that key in in the notepad(servers.txt)?

Thank you in advance.

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
kwhornlcs
Enthusiast
Enthusiast
Jump to solution

Have you tried treating each member of the text file individually like this?

$result = @()

Get-Content c:\STest\servers.txt | ForEach {

    $vm = Get-View  -ViewType VirtualMachine -Filter @{"Name" = $_}

    $obj = new-object psobject

    $obj | Add-Member -MemberType NoteProperty -Name name -Value $vm.Name

    $obj | Add-Member -MemberType NoteProperty -Name CPUSocket -Value $vm.config.hardware.NumCPU

    $obj | Add-Member -MemberType NoteProperty -Name Corepersocket -Value $vm.config.hardware.NumCoresPerSocket

    $result += $obj

}

$result | export-csv -path C:\STest\cpu.txt

View solution in original post

0 Kudos
2 Replies
kwhornlcs
Enthusiast
Enthusiast
Jump to solution

Have you tried treating each member of the text file individually like this?

$result = @()

Get-Content c:\STest\servers.txt | ForEach {

    $vm = Get-View  -ViewType VirtualMachine -Filter @{"Name" = $_}

    $obj = new-object psobject

    $obj | Add-Member -MemberType NoteProperty -Name name -Value $vm.Name

    $obj | Add-Member -MemberType NoteProperty -Name CPUSocket -Value $vm.config.hardware.NumCPU

    $obj | Add-Member -MemberType NoteProperty -Name Corepersocket -Value $vm.config.hardware.NumCoresPerSocket

    $result += $obj

}

$result | export-csv -path C:\STest\cpu.txt

0 Kudos
suelai09
Contributor
Contributor
Jump to solution

Thank you so much kwhornlcs! It works perfectly! The output is exactly what i looking for:)

I have learned something new today, thanks again. Cheers!

0 Kudos