-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOptimize-Computer.ps1
More file actions
292 lines (230 loc) · 10.6 KB
/
Optimize-Computer.ps1
File metadata and controls
292 lines (230 loc) · 10.6 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
Optimizes the performance and workflow of computers on your network.
.DESCRIPTION
The Optimize-Computer script connects to and configures devices on your local network.
Connections are established using PowerShell sessions and your client admin credentials.
Many features are specific to Dell machines, as they require CCTK, Dell's client configuration toolkit. This allows the script to manipulate BIOS settings from Windows. In order for this to be possible, the path to CCTK must be provided. This path can be a network share or a local folder. It can either be provided as an environment variable "cctk" or through the -CCTK parameter.
To undo the script's optimizations, simply run it with no optimization flags. To undo Dell specific optimizations, the -Dell flag must be passed as well.
.PARAMETER ComputerName
Target hostnames. Multiple computers may be passed.
.PARAMETER Fans
Sets the fans to full speed on Dell desktops.
.PARAMETER FillStorage
Creates a file in C:\Users\Public\Downloads occupying most of the disk's remaining space.
.PARAMETER Cores
Sets the processor to only use one core in the BIOS on Dell systems.
.PARAMETER Sleep
Disables sleep. Currently only works on Dell systems.
.PARAMETER USB
Disables all USB and Thunderbolt ports on Dell systems.
.PARAMETER Battery
Causes the battery to remain between 50% and 55% while plugged in on Dell laptops.
.PARAMETER Sound
Disables audio. Currently only works on Dell systems.
.PARAMETER Storage
Disables storage devices in the BIOS on Dell systems. Takes effect on reboot.
.PARAMETER Camera
Disables the camera and microphone on Dell laptops.
.PARAMETER Filter
Enables a reminder to clean the dust filter every 15 days on Dell desktops.
.PARAMETER Cleanup
Deletes left over files, like CCTK. This should happen automatically and is only necessary if execution of the script is interrupted.
.PARAMETER Dell
Specifies the targets must have Dell specific optimizations removed. Only has an effect with no optimization flags.
.PARAMETER CCTKPath
Specifies the path to the folder containing CCTK. This can be a path on the local computer or a network share. An environment variable may be used instead.
.PARAMETER CCTKPass
The password to use with CCTK. This should be the BIOS password on the target (Dell) systems.
.EXAMPLE
.\Optimize-Computer.ps1 -Fans -CCTK C:\cctk\ remote-hostname
Sets the fans to full speed on remote-hostname. Note the path to CCTK is required for this operation.
.LINK
Source: https://github.com/AidanRB/Optimize-Computer
CCTK: https://www.dell.com/support/kbdoc/en-us/000134806/how-to-install-use-dell-client-configuration-toolkit
#>
Param (
[switch] $Fans,
[switch] $FillStorage,
[switch] $Cores,
[switch] $Sleep,
[switch] $USB,
[switch] $Battery,
[switch] $Sound,
[switch] $Storage,
[switch] $Camera,
[switch] $Filter,
[switch] $Cleanup,
[string] $CCTKPath = $env:cctk,
[string] $CCTKPass = $env:cctkpass,
[Parameter(Mandatory, HelpMessage = "Target hosts", Position = 0, ValueFromRemainingArguments)]
[string[]] $ComputerName
)
class ComputerProperties {
[string] $ComputerName
[System.Management.Automation.Runspaces.PSSession] $Session
[bool] $Dell
[string[]] $DellCapabilities
[string[]] $DellCommand
ComputerProperties([string] $ComputerName) {
$this.ComputerName = $ComputerName
}
ComputerProperties([System.Management.Automation.Runspaces.PSSession] $Session) {
$this.ComputerName = $Session.ComputerName
$this.Session = $Session
}
}
class DellOption {
[string] $Enabling = $false
[scriptblock] $DellCheck
[string[]] $EnableCommand
[string[]] $DisableCommand
}
$DellOptions = @{
"Fans" = [DellOption]@{
Enabling = $Fans
DellCheck = { $_ -match "FanCtrlOvrd" }
EnableCommand = "FanCtrlOvrd=Enabled"
DisableCommand = "FanCtrlOvrd=Disabled"
}
"Cores" = [DellOption]@{
Enabling = $Cores
DellCheck = { $_ -match "CpuCore" -or $_ -match "MultipleAtomCores" -or $_ -match "LogicProc" }
EnableCommand = "CpuCore=1", "MultipleAtomCores=1", "LogicProc=Disabled"
DisableCommand = "CpuCore=CoresAll", "MultipleAtomCores=CoresAll", "LogicProc=Enabled"
}
"Sleep" = [DellOption]@{
Enabling = $Sleep
DellCheck = { $_ -match "BlockSleep" }
EnableCommand = "BlockSleep=Enabled"
DisableCommand = "BlockSleep=Disabled"
}
"USB" = [DellOption]@{
Enabling = $USB
DellCheck = { $_ -match "^UsbPorts" -or $_ -match "^ThunderboltPorts" }
EnableCommand = "UsbPortsFront=Disabled", "UsbPortsRear=Disabled", "UsbPortsExternal=Disabled", "ThunderboltPorts=Disabled"
DisableCommand = "UsbPortsFront=Enabled", "UsbPortsRear=Enabled", "UsbPortsExternal=Enabled", "ThunderboltPorts=Enabled"
}
"Battery" = [DellOption]@{
Enabling = $Battery
DellCheck = { $_ -match "PrimaryBattChargeCfg" }
EnableCommand = "PrimaryBattChargeCfg=Custom:5-55"
DisableCommand = "PrimaryBattChargeCfg=Adaptive"
}
"Sound" = [DellOption]@{
Enabling = $Sound
DellCheck = { $_ -match "IntegratedAudio" -or $_ -match "InternalSpeaker" }
EnableCommand = "IntegratedAudio=Disabled", "InternalSpeaker=Disabled"
DisableCommand = "IntegratedAudio=Enabled", "InternalSpeaker=Enabled"
}
"Storage" = [DellOption]@{
Enabling = $Storage
DellCheck = { $_ -match "^M2PcieSsd" -or $_ -match "^Sata" }
EnableCommand = "M2PcieSsd0=Disabled", "M2PcieSsd1=Disabled", "Sata0=Disabled", "Sata1=Disabled", "Sata2=Disabled", "Sata3=Disabled"
DisableCommand = "M2PcieSsd0=Enabled", "M2PcieSsd1=Enabled", "Sata0=Enabled", "Sata1=Enabled", "Sata2=Enabled", "Sata3=Enabled"
}
"Camera" = [DellOption]@{
Enabling = $Camera
DellCheck = { $_ -match "Camera" -or $_ -match "Microphone" }
EnableCommand = "Camera=Disabled", "Microphone=Disabled"
DisableCommand = "Camera=Enabled", "Microphone=Enabled"
}
"Filter" = [DellOption]@{
Enabling = $Filter
DellCheck = { $_ -match "DustFilter" }
EnableCommand = "DustFilter=15days"
DisableCommand = "DustFilter=Disabled"
}
}
# Create sessions
Write-Host -ForegroundColor Blue "Creating sessions..."
$Sessions = New-PSSession $ComputerName
# Show created sessions
Write-Host -ForegroundColor Green -NoNewline "Created sessions:"
$Sessions.ForEach({ Write-Host -NoNewline " $($_.ComputerName)" })
Write-Host
# Create hashtable of computers
$Computers = @{}
$Sessions | ForEach-Object {
$Computers.Add($_.ComputerName, [ComputerProperties]::new([System.Management.Automation.Runspaces.PSSession]$_))
}
# Cleanup in case old temp files exist
Invoke-Command -Session $Sessions -ScriptBlock { Remove-Item -Recurse C:\Temp\cctk } -ErrorAction SilentlyContinue
# Exit now if $Cleanup
if ($Cleanup) {
# Remove all sessions if cleanup is requested
Remove-PSSession *
Exit
}
# Detect Dell computers and copy CCTK if we know where it is
if ($CCTKPath) {
# Check to see what targets are Dell
foreach ($Session in $Sessions) {
if (Invoke-Command -Session $Session -ScriptBlock { (Get-CimInstance win32_computersystem).Manufacturer -like "Dell*" }) {
$Computers[$Session.ComputerName].Dell = $true
}
}
# Show Dell computers
Write-Host -ForegroundColor Green -NoNewline "Identified Dell computers:"
($Computers | Where-Object { $_.Values.Dell }).GetEnumerator().ForEach({ Write-Host -NoNewline " $($_.Key)" })
Write-Host
Write-Host -ForegroundColor Blue -NoNewline "Copying CCTK:"
# Copy CCTK in parallel to each Dell computer
($Computers | Where-Object { $_.Values.Dell }).GetEnumerator() | ForEach-Object -Parallel {
Write-Host -NoNewline " $($_.Key)"
Invoke-Command -Session $_.Value.Session -ScriptBlock {
New-Item -Path C:\Temp\cctk -ItemType Directory -ErrorAction SilentlyContinue | Out-Null
}
Copy-Item -ToSession $_.Value.Session $(($using:CCTKPath) + '\*') -Destination C:\Temp\cctk\
}
Write-Host
# Get available BIOS settings
Write-Host -ForegroundColor Blue -NoNewline "Detecting capabilities..."
($Computers | Where-Object { $_.Values.Dell }).GetEnumerator() | ForEach-Object -Parallel {
$_.Value.DellCapabilities = (Invoke-Command -Session $_.Value.Session -ScriptBlock {
c:\Temp\cctk\cctk.exe -H
}).Split().Where({ $_ -match '--' }).Split('--').Where({ $_ -notmatch '\*' -and $_ -ne '' -and $_ -notmatch 'option\[=argument\]' }) | Sort-Object
Write-Host -ForegroundColor Green -NoNewline " $($_.Key)"
}
Write-Host
}
# Apply settings
$Computers.GetEnumerator() | Foreach-Object -Parallel {
$Computer = $_
# If we're settings any Dell options, put together the command for them
if (($Using:DellOptions).Values.Enabling -contains $True) {
foreach ($Option in ($Using:DellOptions).GetEnumerator()) {
if ($Option.Value.Enabling -EQ $true -and ($Computer.Value.DellCapabilities | Where-Object -FilterScript $Option.Value.DellCheck)) {
foreach ($Command in $Option.Value.EnableCommand) {
if ($Command.Split('=')[0] -in $Computer.Value.DellCapabilities) {
$Computer.Value.DellCommand += "--$Command"
}
}
}
}
}
# If no Dell options are set, reset them all
else {
foreach ($Option in ($Using:DellOptions).GetEnumerator()) {
if ($Computer.Value.DellCapabilities | Where-Object -FilterScript $Option.Value.DellCheck) {
foreach ($Command in $Option.Value.DisableCommand) {
if ($Command.Split('=')[0] -in $Computer.Value.DellCapabilities) {
$Computer.Value.DellCommand += "--$Command"
}
}
}
}
}
Write-Host -ForegroundColor Blue -NoNewline "Configuring $($Computer.Key): "
Write-Host "$($Computer.Value.DellCommand)"
# Run cctk
Invoke-Command -Session $Computer.Value.Session -ScriptBlock {
param($Computer, $CCTKPass)
Start-Process -Wait -FilePath "C:\Temp\cctk\cctk.exe" -ArgumentList @($Computer.Value.DellCommand + "--ValSetupPwd=$CCTKPass")
Write-Host -ForegroundColor Green "Configured $($Computer.Key)."
} -ArgumentList $Computer, $using:CCTKPass
}
# Cleanup
Write-Host -ForegroundColor Blue "Cleaning up..."
Invoke-Command -Session $Sessions -ScriptBlock { Remove-Item -Recurse C:\Temp\cctk }
$Sessions | Remove-PSSession