-
Notifications
You must be signed in to change notification settings - Fork 126
Expand file tree
/
Copy pathWOL.ps1
More file actions
292 lines (269 loc) · 10.5 KB
/
WOL.ps1
File metadata and controls
292 lines (269 loc) · 10.5 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
<#
.SYNOPSIS
Wake-On-LAN
.DESCRIPTION
A description of the file.
.PARAMETER ConsoleTitle
Title for PowerShell console
.PARAMETER BIOSPassword
A description of the BIOSPassword parameter.
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2022 v5.8.209
Created on: 8/1/2022 8:16 AM
Created by: Mick Pletcher
Filename: WOL.ps1
===========================================================================
#>
param
(
[ValidateNotNullOrEmpty()]
[string]$ConsoleTitle,
[string]$BIOSPassword
)
function Set-BIOS {
<#
.SYNOPSIS
Configure WOL in BIOS
.DESCRIPTION
Configure WOL in BIOS
#>
[CmdletBinding()]
param ()
#Import Dell BIOS Provider PowerShell Module
Try {
Import-Module -Name DellBIOSProvider
}
catch {
Find-Module -Name DellBIOSProvider | Install-Module -Force
Import-Module -Name DellBIOSProvider
}
#Set Wake-On-LAN to LanOnly
$BIOSItem = "PowerManagement\WakeOnLan"
$NewValue = "LanWlan"
#Check if LanWlan is available
If ($NewValue -notin ("DellSmBios:\" + $BIOSItem).PossibleValues) {
$NewValue = "LanOnly"
}
If (Get-Item -Path ("DellSmBios:\" + $BIOSItem) -ErrorAction SilentlyContinue) {
Write-Host ("BIOS" + [char]32 + $BIOSItem.split('\')[1] + ":" + [char]32) -NoNewline
If ((Get-Item -Path ("DellSmBios:\" + $BIOSItem)).CurrentValue -ne $NewValue) {
If ($BIOSPassword) {
Set-Item -Path ("DellSmBios:\" + $BIOSItem) -Value $NewValue -Force -Password $BIOSPassword
} else {
Set-Item -Path ("DellSmBios:\" + $BIOSItem) -Value $NewValue -Force
}
If ((Get-Item -Path ("DellSmBios:\" + $BIOSItem)).CurrentValue -eq $NewValue) {
Write-Host $NewValue -ForegroundColor Yellow
}
else {
Write-Host (Get-Item -Path ("DellSmBios:\" + $BIOSItem)).CurrentValue -ForegroundColor Red
}
}
else {
Write-Host $NewValue -ForegroundColor Yellow
}
}
#Disable CState Control
$BIOSItem = "Performance\CStatesCtrl"
$NewValue = "Disabled"
#Test if CState exists
If (Get-Item -Path ("DellSmBios:\" + $BIOSItem) -ErrorAction SilentlyContinue) {
Write-Host ("BIOS" + [char]32 + $BIOSItem.split('\')[1] + ":" + [char]32) -NoNewline
If ((Get-Item -Path ("DellSmBios:\" + $BIOSItem)).CurrentValue -ne $NewValue) {
If ($BIOSPassword) {
Set-Item -Path ("DellSmBios:\" + $BIOSItem) -Value $NewValue -Force -Password $BIOSPassword
}
else {
Set-Item -Path ("DellSmBios:\" + $BIOSItem) -Value $NewValue -Force
}
If ((Get-Item -Path ("DellSmBios:\" + $BIOSItem)).CurrentValue -eq $NewValue) {
Write-Host $NewValue -ForegroundColor Yellow
}
else {
Write-Host (Get-Item -Path ("DellSmBios:\" + $BIOSItem)).CurrentValue -ForegroundColor Red
}
}
else {
Write-Host $NewValue -ForegroundColor Yellow
}
}
#Disable Deep Sleep
$BIOSItem = "PowerManagement\DeepSleepCtrl"
$NewValue = "Disabled"
#Test if Deep Sleep exists
If (Get-Item -Path ("DellSmBios:\" + $BIOSItem) -ErrorAction SilentlyContinue) {
Write-Host ("BIOS" + [char]32 + $BIOSItem.split('\')[1] + ":" + [char]32) -NoNewline
If ((Get-Item -Path ("DellSmBios:\" + $BIOSItem)).CurrentValue -ne $NewValue) {
If ($BIOSPassword) {
Set-Item -Path ("DellSmBios:\" + $BIOSItem) -Value $NewValue -Force -Password $BIOSPassword
}
else {
Set-Item -Path ("DellSmBios:\" + $BIOSItem) -Value $NewValue -Force
}
If ((Get-Item -Path ("DellSmBios:\" + $BIOSItem)).CurrentValue -eq $NewValue) {
Write-Host $NewValue -ForegroundColor Yellow
}
else {
Write-Host (Get-Item -Path ("DellSmBios:\" + $BIOSItem)).CurrentValue -ForegroundColor Red
}
}
else {
Write-Host $NewValue -ForegroundColor Yellow
}
}
#Disable Block S3
$BIOSItem = "PowerManagement\BlockS3"
$NewValue = "Disabled"
#Test if Block S3 exists
If (Get-Item -Path ("DellSmBios:\" + $BIOSItem) -ErrorAction SilentlyContinue) {
Write-Host ("BIOS" + [char]32 + $BIOSItem.split('\')[1] + ":" + [char]32) -NoNewline
If ((Get-Item -Path ("DellSmBios:\" + $BIOSItem)).CurrentValue -ne $NewValue) {
If ($BIOSPassword) {
Set-Item -Path ("DellSmBios:\" + $BIOSItem) -Value $NewValue -Force -Password $BIOSPassword
}
else {
Set-Item -Path ("DellSmBios:\" + $BIOSItem) -Value $NewValue -Force
}
If ((Get-Item -Path ("DellSmBios:\" + $BIOSItem)).CurrentValue -eq $NewValue) {
Write-Host $NewValue -ForegroundColor Yellow
}
else {
Write-Host (Get-Item -Path ("DellSmBios:\" + $BIOSItem)).CurrentValue -ForegroundColor Red
}
}
else {
Write-Host $NewValue -ForegroundColor Yellow
}
}
#Disable C States
$BIOSItem = "PowerManagement\CStatesCtrl"
$NewValue = "Disabled"
#Test if CStatesCtrl exists
If (Get-Item -Path ("DellSmBios:\" + $BIOSItem) -ErrorAction SilentlyContinue) {
Write-Host ("BIOS" + [char]32 + $BIOSItem.split('\')[1] + ":" + [char]32) -NoNewline
If ((Get-Item -Path ("DellSmBios:\" + $BIOSItem)).CurrentValue -ne $NewValue) {
If ($BIOSPassword) {
Set-Item -Path ("DellSmBios:\" + $BIOSItem) -Value $NewValue -Force -Password $BIOSPassword
}
else {
Set-Item -Path ("DellSmBios:\" + $BIOSItem) -Value $NewValue -Force
}
If ((Get-Item -Path ("DellSmBios:\" + $BIOSItem)).CurrentValue -eq $NewValue) {
Write-Host $NewValue -ForegroundColor Yellow
}
else {
Write-Host (Get-Item -Path ("DellSmBios:\" + $BIOSItem)).CurrentValue -ForegroundColor Red
}
}
else {
Write-Host $NewValue -ForegroundColor Yellow
}
}
}
Function Set-AdvancedNIC {
#Get the Ethernet NIC
$NIC = Get-NetAdapter | Where-Object {($_.PhysicalMediaType -eq '802.3') -and ($_.Status -eq 'Up')}
#Disable Energy Efficient Ethernet setting so NIC does not go to sleep
#Two variants of Energy Efficient Exist on different Dell models
#Check if Energy-Efficient Ethernet Exists
If (Get-NetAdapterAdvancedProperty -Name $NIC.Name -DisplayName 'Energy-Efficient Ethernet' -ErrorAction SilentlyContinue) {
Write-Host 'NIC Energy-Efficient Ethernet: ' -NoNewline
Set-NetAdapterAdvancedProperty -Name $NIC.Name -DisplayName 'Energy-Efficient Ethernet' -DisplayValue 'Disabled'
If ((Get-NetAdapterAdvancedProperty -Name $NIC.Name -DisplayName 'Energy-Efficient Ethernet').DisplayValue -eq 'Disabled') {
Write-Host 'Disabled' -ForegroundColor Yellow
}
else {
Write-Host 'Enabled' -ForegroundColor Red
}
}
#Check if Energy Efficient Ethernet Exists
If (Get-NetAdapterAdvancedProperty -Name $NIC.Name -DisplayName 'Energy Efficient Ethernet' -ErrorAction SilentlyContinue) {
Write-Host 'NIC Energy Efficient Ethernet: ' -NoNewline
Set-NetAdapterAdvancedProperty -Name $NIC.Name -DisplayName 'Energy Efficient Ethernet' -DisplayValue 'Off'
If ((Get-NetAdapterAdvancedProperty -Name $NIC.Name -DisplayName 'Energy Efficient Ethernet').DisplayValue -eq 'Off') {
Write-Host 'Off' -ForegroundColor Yellow
}
else {
Write-Host 'On' -ForegroundColor Red
}
}
#Turn on Wake on Magic Packet
#Check if Wake on Magic Packet Exists
If (Get-NetAdapterAdvancedProperty -Name $NIC.Name -DisplayName 'Wake on Magic Packet' -ErrorAction SilentlyContinue) {
Write-Host 'NIC Wake on Magic Packet: ' -NoNewline
Set-NetAdapterAdvancedProperty -Name $NIC.Name -DisplayName 'Wake on Magic Packet' -RegistryKeyword '*WakeOnMagicPacket' -RegistryValue 1
If ((Get-NetAdapterAdvancedProperty -Name $NIC.Name -DisplayName 'Wake on Magic Packet').DisplayValue -eq 'Enabled') {
Write-Host 'Enabled' -ForegroundColor Yellow
}
else {
Write-Host 'Disabled' -ForegroundColor Red
}
}
#Shutdown WakeOnLAN
If (Get-NetAdapterAdvancedProperty -Name $NIC.Name -DisplayName 'Shutdown Wake-On-Lan' -ErrorAction SilentlyContinue) {
Write-Host 'NIC Shutdown Wake-On-Lan: ' -NoNewline
Set-NetAdapterAdvancedProperty -Name $NIC.Name -DisplayName 'Shutdown Wake-On-Lan' -DisplayValue 'Enabled'
If ((Get-NetAdapterAdvancedProperty -Name $NIC.Name -DisplayName 'Shutdown Wake-On-Lan').DisplayValue -eq 'Enabled') {
Write-Host 'Enabled' -ForegroundColor Yellow
}
else {
Write-Host 'Disabled' -ForegroundColor Red
}
}
}
function Set-PowerManagement {
<#
.SYNOPSIS
Enable Power Management
.DESCRIPTION
A detailed description of the Set-PowerManagement function.
.EXAMPLE
PS C:\> Set-PowerManagement
.NOTES
Additional information about the function.
#>
[CmdletBinding()]
param ()
#Turn off Hibernation
Write-Host ("OS Hiberboot:" + [char]32) -NoNewline
If ((Get-ItemProperty -Path REGISTRY::"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Power").HiberbootEnabled -ne 0) {
Set-ItemProperty -Path REGISTRY::"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Power" -Name HiberbootEnabled -Value 0 -Force
}
If ((Get-ItemProperty -Path REGISTRY::"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Power").HiberbootEnabled -eq 0) {
Write-Host "Disabled" -ForegroundColor Yellow
} else {
Write-Host "Enabled" -ForegroundColor Red
}
#0 = Option 1 & 2 checked
#10 = Option 1 checked, 2 & 3 cleared
#24 = Option 1 unchecked
#256 = Option 1, 2, & 3 all checked
#264 = Option 2 & 3 Checked
#272 = Option 1 checked
#280 = Option 2 & 3 checked
$PNPValue = 256
$Adapter = Get-NetAdapter | Where-Object { ($_.Status -eq 'Up') -and ($_.PhysicalMediaType -eq '802.3') }
$KeyPath = 'HKLM:\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\'
foreach ($Entry in (Get-ChildItem $KeyPath -ErrorAction SilentlyContinue).Name) {
If ((Get-ItemProperty REGISTRY::$Entry).DriverDesc -eq $Adapter.InterfaceDescription) {
$Value = (Get-ItemProperty REGISTRY::$Entry).PnPCapabilities
If ($Value -ne $PnPValue) {
Set-ItemProperty -Path REGISTRY::$Entry -Name PnPCapabilities -Value $PnPValue -Force
Disable-PnpDevice -InstanceId $Adapter.PnPDeviceID -Confirm:$false
Enable-PnpDevice -InstanceId $Adapter.PnPDeviceID -Confirm:$false
$Value = (Get-ItemProperty REGISTRY::$Entry).PnPCapabilities }
If ($Value -eq $PnPValue) {
Write-Host 'Allow the computer to turn off this device is configured' -ForegroundColor Yellow
} else {
Write-Host 'Allow the computer to turn off this device Failed' -ForegroundColor Red
Exit 1
}
}
}
}
#Set Console Title
$host.ui.RawUI.WindowTitle = $ConsoleTitle
Set-BIOS
Set-AdvancedNIC
Set-PowerManagement