Scripts/Get-PCProcessor.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
Function Get-PCProcessor {

    <#
 
    .SYNOPSIS
    Get processor information
 
    .DESCRIPTION
    Get processor information
 
    .PARAMETER ComputerName
    The target computer name
 
    .EXAMPLE
    Get-PCProcessor -ComputerName LabPC2024
 
    .NOTES
    N/A
 
    .LINK
    N/A
 
    #>


    [CmdletBinding ()]

    Param (

        [Parameter (Mandatory = $True,
                    ValueFromPipeline = $True,
                    ValueFromPipelineByPropertyName = $True,
                    HelpMessage = 'Enter computer name'
                   )
        ]

        [String[]]$ComputerName

    )

    BEGIN {

        $CPUAvailability = @{

            '1' = 'Other'
            '2' = 'Unknown'
            '3' = 'Running/Full power'
            '4' = 'Warning'
            '5' = 'In test'
            '6' = 'Not applicable'
            '7' = 'Power off'
            '8' = 'Off line'
            '9' = 'Off duty'
            '10' = 'Degraded'
            '11' = 'Not installed'
            '12' = 'Install error'
            '13' = 'Power save/Unknown'
            '14' = 'Power save/Low power mode'
            '15' = 'Power save/Standby'
            '16' = 'Power cycle'
            '17' = 'Power save/Warning'
            '18' = 'Paused'
            '19' = 'Not ready'
            '20' = 'Not configured'
            '21' = 'Quiet'

        }

        $CPUStatus = @{

            '0' = 'Unknown'
            '1' = 'Enabled'
            '2' = 'Disabled by user via BIOS setup'
            '3' = 'CPU disabled by BIOS (POST error)'
            '4' = 'Idle'
            '5' = 'Reserved'
            '6' = 'Reserved'
            '7' = 'Other'

        }

        $CPUType = @{

            '1' = 'Other'
            '2' = 'Unknown'
            '3' = 'Central processor'
            '4' = 'Math processor'
            '5' = 'DSP processor'
            '6' = 'Video processor'

        }

        $CPUArchitecture = @{

            '0' = 'x86'
            '1' = 'MIPS'
            '2' = 'Alpha'
            '3' = 'PowerPC'
            '5' = 'ARM'
            '6' = 'ia64'
            '9' = 'x64'

        }

        Function Show-Output ($Computer, $Values, $Status) {

            [PSCustomObject]@{

                ComputerName = $Computer
                Caption = $Values.Caption
                DeviceID = $Values.DeviceID
                Manufacturer = $Values.Manufacturer
                MaxClockSpeed = "$($Values.MaxClockSpeed / 1000)$(' GHz')"
                Name = $Values.Name
                SocketDesignation = $Values.SocketDesignation
                Availability = $CPUAvailability["$($Values.Availability)"]
                AddressWidth =  $Values.AddressWidth
                DataWidth = $Values.DataWidth
                L2CacheSize = $Values.L2CacheSize
                L2CacheSpeed = $Values.L2CacheSpeed
                PowerManagementSupported = $Values.PowerManagementSupported
                ProcessorType = $CPUType["$($Values.ProcessorType)"]
                Revision = $Values.Revision
                CPUStatus = $CPUStatus["$($Values.CPUStatus)"]
                Architecture = $CPUArchitecture["$($Values.Architecture)"]
                NumberOfCores = $Values.NumberOfCores
                NumberOfEnabledCore = $Values.NumberOfEnabledCore
                NumberOfLogicalProcessors = $Values.NumberOfLogicalProcessors
                ThreadCount = $Values.ThreadCount
                ProcessorID = $Values.ProcessorId
                VirtualizationFirmwareEnabled = $Values.VirtualizationFirmwareEnabled
                VMMonitorModeExtensions = $Values.VMMonitorModeExtensions
                Status = $Status

            }

        }

    }

    PROCESS {

        ForEach ($Computer In $ComputerName) {

            If (Test-Connection -ComputerName $Computer -Count 1 -Quiet) {

                Try {

                    $Data = Get-WmiObject Win32_Processor -ComputerName $Computer | Select-Object *

                    ForEach ($Item In $Data) {

                        Show-Output $Computer.ToUpper() $Item 'Ok'

                    }

                }

                Catch {

                    Show-Output $Computer.ToUpper() $Null $PSItem.Exception.Message

                }

            }

            Else {

                Show-Output $Computer.ToUpper() $Null 'Unreachable'

            }

        }

    }

    END {}

}