forked from nullzeroio/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Get-ProcessorInventory.ps1
127 lines (96 loc) · 3.68 KB
/
Get-ProcessorInventory.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<#
.SYNOPSIS
Returns information about the Processor via WMI.
.DESCRIPTION
Information about the processor is returned using the Win32_Processor WMI class.
You can provide a single computer/server name or supply an array/list.
.PARAMETER Computers
Single computer name, list of computers or .txt file containing a list of computers.
.EXAMPLE
.\Get-ProcessorInventory.ps1 -Computers (Get-Content C:\ComputerList.txt)
.EXAMPLE
.\Get-ProcessorInventory.ps1 -Computers Test-Server.company.com
.EXAMPLE
.\Get-ProcessorInventory.ps1 -Computers SERVER1.company.com,SERVER2.company.com | Format-Table -AutoSize
.EXAMPLE
.\Get-ProcessorInventory.ps1 -Computers SERVER1.company.com,SERVER2.company.com | Export-Csv C:\ProcInv.csv -NoTypeInformation
.INPUTS
System.String
.OUTPUTS
Selected.System.Management.ManagementObject
.NOTES
#=======================================================
Author: Kevin Kirkpatrick
Created: 4/16/14
Disclaimer: This script comes with no implied warranty or guarantee and is to be used at your own risk. It's recommended that you TEST
execution of the script against Dev/Test before running against any Production system.
#========================================================
TAG:PUBLIC
.LINK
https://github.com/vScripter/PowerShell-Scripts
.LINK
about_WMi
.LINK
about_Wmi_Cmdlets
#>
#Requires -Version 3
[cmdletbinding()]
Param (
[parameter(Mandatory = $true,
ValueFromPipeline = $true,
HelpMessage = "Enter the name of a computer or an array of computer names")]
[system.string[]]$Computers
)
# Set the EA preference to 'Stop' so that Non-Terminating errors will be caught and displayed in the catch block
$ErrorActionPreference = "Stop"
# Cycle through each computer and attempt to query WMI
foreach ($C in $Computers)
{
# Test the connection to the computer, if it pings, continue on with the query
if (Test-Connection -ComputerName $C -Count 1 -Quiet)
{
try
{
#region FormattingHashTables
#================================
# Attempt to differentiate if the destination is a VM, or not. In VMware, vProcessors typically return a value of 0 for the L2 Processor Cache.
# This was not testing with Hyper-V
$Type = @{
label = 'Type'
expression = {
if ($_.L2CacheSize -eq '0') { "Virtual" }
else { "Physical" }
}
}# end $Type
# Check to see if HyperThreading is enabled by comparing the number of logical processors with the number of cores
$HyperThreading = @{
label = 'HyperthreadingEnabled'
expression = {
if ($_.NumberOfLogicalProcessors -gt $_.NumberOfCores) { "Yes" }
else { "No" }
}
}# end $HyperThreading
# Use hash tables to modify the paramter output names
$ComputerName = @{ label = 'Computer'; Expression = { $_.PSComputerName } }
$CoreCount = @{ label = 'CoreCount'; Expression = { $_.NumberOfCores } }
$LogicalCores = @{ label = 'LogicalProcessors'; expression = { $_.NumberOfLogicalProcessors } }
$Description = @{ label = 'Description'; Expression = { $_.Name } }
$Socket = @{ label = 'Socket'; expression = { $_.SocketDesignation } }
#================================
#endregion
# Run the query
Get-WmiObject -Query "SELECT * FROM win32_processor" -ComputerName $C |
Select-Object $ComputerName, $Socket, $CoreCount, $LogicalCores, $HyperThreading, $Description, $Type
}# end try
catch
{
# Catch any errors and write a warning that includes the computer name as well as the error message, which is stored in $_
Write-Warning "$C - $_"
}# end catch
}# end if
else
{
# If the computer was not reachable on the network, display such detail
Write-Warning "$C is unreachable"
}# end else
}# end foreach