You can do this with a WMI request. The following script puts the SocketDesignation name for each logical processor in the database table for the list of servers in the csv file. After filling out the table, the following query will give you the number of physical and logical processors:
select servername, COUNT(cpuname) 'LogicalCPUCount', COUNT(distinct cpuname) 'PhysicalCPUCount'
from tmp_cpu
group by servername
***** WMI script - you will need to configure connections and create a tmp_cpu table before starting *****
$query = "delete sqlserverinventory.dbo.tmp_cpu"
Invoke-Sqlcmd -Query $query -ServerInstance "xxxxxxxx"
Invoke-Sqlcmd -Query "select servername from sqlserverinventory.dbo.server where servername in (select servername from sqlserverinventory.dbo.vw_Instance_Autoload);" -ServerInstance "xxxxxxxx" | out-file -filepath "v:\scripts\server_list.csv"
(Get-Content v:\scripts\server_list.csv) | where {$_.readcount -gt 3} | Set-Content v:\scripts\server_list.csv
$servers = Get-Content "V:\scripts\server_list.csv"
foreach ($server in $servers){
$server = $server.Trim()
$SQLServices = Get-WmiObject -ComputerName $server -Namespace "root\CIMV2" -query "SELECT SocketDesignation FROM Win32_Processor where CPUStatus=1 or CPUStatus=4"
forEach ($SQLService in $SQLServices) {
$PhysicalCPU = $SQLService.SocketDesignation
$insert_query = "INSERT INTO sqlserverinventory.dbo.tmp_cpu (ServerName,CPUName) VALUES('$server','$PhysicalCPU')"
Invoke-Sqlcmd -Query $insert_query -ServerInstance "xxxxxxxx"
}
}
Mike ryder
source
share