-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheck for Driver Issues for Windows.ps1
More file actions
166 lines (129 loc) · 4.69 KB
/
Check for Driver Issues for Windows.ps1
File metadata and controls
166 lines (129 loc) · 4.69 KB
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
<#
.NOTES
===========================================================================
Name: Check for Driver Issues for Windows
Purpose: Use with immybot
Created by: Chris Dewey
Updated: 2026.02.15
Version: 1.0
===========================================================================
.DESCRIPTION
This will check the system for any Driver related issues and will report back
to immybot and indicate a non compliant if there is a driver issue. If there
is no issues it will be marked as compliant
#>
param (
[string]$LogPath = "C:\Source\Logs"
)
# -----------------------------
# Script Configuration
# -----------------------------
$Date = (Get-Date).ToString("yyyyMMdd")
$LogFileName = "${Date}_Driver-Error-Detection-Logs-$env:COMPUTERNAME.txt"
$LogFilePath = Join-Path -Path $LogPath -ChildPath $LogFileName
# -----------------------------
# Helper: Ensure Log Directory
# -----------------------------
function Ensure-LogFolder {
if (-not (Test-Path -Path $LogPath)) {
Write-Host "Creating log directory: $LogPath"
New-Item -ItemType Directory -Path $LogPath -Force | Out-Null
}
}
# -----------------------------
# Helper: Get Problem Devices
# -----------------------------
function Get-ProblemDevices {
# ConfigManagerErrorCode > 0 indicates device/driver issue
$devices = Get-CimInstance -ClassName Win32_PnpEntity -Namespace root\cimv2 |
Where-Object { $_.ConfigManagerErrorCode -gt 0 }
return $devices
}
# -----------------------------
# Helper: Write Log Output
# -----------------------------
function Write-DriverLog {
Ensure-LogFolder
$devices = Get-ProblemDevices
"===================================================" | Out-File $LogFilePath -Append
"Driver Error Detection Report" | Out-File $LogFilePath -Append
"Computer : $env:COMPUTERNAME" | Out-File $LogFilePath -Append
"Date : $(Get-Date)" | Out-File $LogFilePath -Append
"===================================================" | Out-File $LogFilePath -Append
"" | Out-File $LogFilePath -Append
if ($devices) {
"ERRORS FOUND IN DEVICE MANAGER" | Out-File $LogFilePath -Append
"-------------------------------------------" | Out-File $LogFilePath -Append
$devices |
Select-Object Name, ConfigManagerErrorCode |
Format-Table -AutoSize |
Out-String |
Out-File $LogFilePath -Append
"" | Out-File $LogFilePath -Append
"ACTION: Please review driver issues manually." | Out-File $LogFilePath -Append
Write-Host "NOT COMPLIANT - Driver/device errors found."
Write-Host "Log written to: $LogFilePath"
return $false
}
else {
"No driver/device errors detected." | Out-File $LogFilePath -Append
Write-Host "COMPLIANT - No Device Manager errors found."
Write-Host "Log written to: $LogFilePath"
return $true
}
}
# -----------------------------
# ImmyBot Required Switch
# -----------------------------
switch ($Method) {
# -------------------------
# GET MODE
# -------------------------
"Get" {
Write-Host "=== GET MODE ==="
$devices = Get-ProblemDevices
Write-Host "Log Path: $LogFilePath"
Write-Host "Problem Devices Found: $($devices.Count)"
# Return device list for visibility
$devices | Select-Object Name, ConfigManagerErrorCode
break
}
# -------------------------
# TEST MODE (Detect/Verify)
# -------------------------
"Test" {
Write-Host "=== TEST MODE (Detect / Verify) ==="
$devices = Get-ProblemDevices
if ($devices.Count -gt 0) {
Write-Host "Result: NOT COMPLIANT - Device errors detected."
$false
}
else {
Write-Host "Result: COMPLIANT - No device errors detected."
$true
}
break
}
# -------------------------
# SET MODE (Execute)
# -------------------------
"Set" {
Write-Host "=== SET MODE (Execute) ==="
Write-Host "Generating driver error report..."
$ok = Write-DriverLog
if ($ok) {
Write-Host "SET Result: Success (No errors present)"
$true
}
else {
Write-Host "SET Result: Completed (Errors logged for review)"
$true # Still return true because remediation is logging/reporting
}
break
}
default {
Write-Host "ERROR: Unknown `$Method value: $Method"
$false
break
}
}