Public/Hardware/Get-CPUInfo.ps1
<#
Copyright © 2024 Integris. For internal company use only. All rights reserved. #> FUNCTION Get-CPUInfo { <# .SYNOPSIS Retrieves and evaluates CPU information from the local machine. .DESCRIPTION This function gathers detailed information about the CPU(s) on the local machine, including model, benchmark scores, age, and performance rating. It uses the model name to look up benchmark data and calculates a performance rating based on the benchmark score. .PARAMETER None This function does not take any parameters. .EXAMPLE Get-CPUDevice This command retrieves and displays CPU information for the local machine, including model, benchmark score, age, and performance rating. .NOTES The function relies on web data from www.cpubenchmark.net to obtain CPU performance data. #> $Results = @() $CPUs = Get-CIMInstance win32_Processor $StringsToRemove = @('\([^()]*\)',"CPU ") FOREACH ($CPU in $CPUs) { $WorkstationProcessorName = $CPU.name FOREACH ($String in $StringsToRemove) { $WorkstationProcessorName = $WorkstationProcessorName -Replace $String,"" } IF ($WorkstationProcessorName -match '\b(\w+-?\d+\w*)\b') { $Model = $WorkstationProcessorName } ELSE { $Model = "Unknown Model" } # Grab Benchmark Data using $Model as a lookup value $BenchmarkResults = Invoke-BenchmarkScraper -Query $Model -Limit 1 IF ($BenchmarkResults) { # Set CPUScore to the value from the Lookup [int]$CPUScore = $BenchmarkResults.cpumark [string]$CPUDate = $BenchmarkResults.date $CPUAge = [Math]::Round((((Get-Date) - (Get-Date -Date $CPUDate)).Days/365.25), 2) } ELSEIF ($BenchmarkResults.count -gt 1) { # Set CPUScore to the value from the first result in the Lookup [int]$CPUScore = $BenchmarkResults[0].cpumark [string]$CPUDate = $BenchmarkResults[0].date $CPUAge = [Math]::Round((((Get-Date) - (Get-Date -Date $CPUDate)).Days/365.25), 2) } ELSE { [int]$CPUScore = 0 [string]$CPUDate = "Unknown" $CPUAge = "Unknown" } IF ($CPUScore -gt 40000) { $CPURating = 9; $CPURatingString = "Crazy Fast" } ELSEIF ($CPUScore -gt 25000) { $CPURating = 8; $CPURatingString = "Extrmemly Fast" } ELSEIF ($CPUScore -gt 17500) { $CPURating = 7; $CPURatingString = "Very Fast" } ELSEIF ($CPUScore -gt 12000) { $CPURating = 6; $CPURatingString = "Fast" } ELSEIF ($CPUScore -gt 8000) { $CPURating = 5; $CPURatingString = "Good" } ELSEIF ($CPUScore -gt 5500) { $CPURating = 4; $CPURatingString = "Acceptable" } ELSEIF ($CPUScore -gt 4000) { $CPURating = 3; $CPURatingString = "Slow" } ELSEIF ($CPUScore -gt 3000) { $CPURating = 2; $CPURatingString = "Very Slow" } ELSEIF ($CPUScore -gt 0) { $CPURating = 1; $CPURatingString = "Extremely Slow" } ELSE { $CPURating = "Unknown"; $CPURatingString = "Unknown" } $Results += New-Object PSObject -WarningAction SilentlyContinue -Property @{ Hostname = $env:COMPUTERNAME Socket = $CPU.SocketDesignation CPUModel = $WorkstationProcessorName CPUScore = $CPUScore YearsOld = $CPUAge NumberOfCores = $CPU.NumberOfCores NumberOfThreads = $CPU.ThreadCount CPURating = $CPURating CPURatingString = $CPURatingString } } RETURN $Results | Select-Object Hostname, Socket, CPUModel, CPUScore, YearsOld, NumberOfCores, NumberOfThreads, CPURating, CPURatingString } New-Alias -Name Get-CPUDevice -Value Get-CPUInfo |