-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSNTL-PS-Functions.txt
836 lines (717 loc) · 28.6 KB
/
SNTL-PS-Functions.txt
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
Function Get-USBPath {
<#
.SYNOPSIS
Gets the path for the data folder on your install USB drive.
.PARAMETER DriveName
Required. The name of the usb drive
.PARAMETER FolderName
Optional. The name of the data folder on drive.
.EXAMPLE
Get-USBDataFolder -DriveName "Data" -FolderName "MyFolder"
#>
Param (
[Parameter(Mandatory = $True)]
[String] $DriveName,
[Parameter(Mandatory = $False)]
[String] $FolderName
)
$DriveLetter = (Get-WmiObject Win32_Volume | Where-Object Label -Like $DriveName).DriveLetter
$FolderPath = "{0}\{1}" -f $DriveLetter, $FolderName
If (Test-Path $FolderPath) {
Return $FolderPath
}
Else {
Return $null
}
}
Function Add-WifiNetwork {
<#
.SYNOPSIS
Adds a wireless profile with the supplied parameters via netsh.
Does not connect to the wifi network.
.PARAMETER NetworkSSID
The name of the wireless network.
.PARAMETER NetworkPassword
The password of the wireless network.
.PARAMETER Authentication
The authentication type. Default: WPA2PSK
.PARAMETER Encryption
The encryption method. Default: AES
.EXAMPLE
Add-WifiNetwork -NetworkSSID "WiFi Name" -NetworkPassword "Pass12345"
#>
param
(
[Parameter(Mandatory = $False)]
[string]$NetworkSSID,
[Parameter(Mandatory = $true)]
[string]$NetworkPassword,
[ValidateSet('WEP', 'WPA', 'WPA2', 'WPA2PSK')]
[Parameter(Mandatory = $False)]
[string]$Authentication = 'WPA2PSK',
[ValidateSet('AES', 'TKIP')]
[Parameter(Mandatory = $False)]
[string]$Encryption = 'AES'
)
# Create the WiFi profile, set the profile to auto connect
$WirelessProfile = @'
<WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">
<name>{0}</name>
<SSIDConfig>
<SSID>
<name>{0}</name>
</SSID>
</SSIDConfig>
<connectionType>ESS</connectionType>
<connectionMode>auto</connectionMode>
<MSM>
<security>
<authEncryption>
<authentication>{2}</authentication>
<encryption>{3}</encryption>
<useOneX>false</useOneX>
</authEncryption>
<sharedKey>
<keyType>passPhrase</keyType>
<protected>false</protected>
<keyMaterial>{1}</keyMaterial>
</sharedKey>
</security>
</MSM>
</WLANProfile>
'@ -f $NetworkSSID, $NetworkPassword, $Authentication, $Encryption
# Create the XML file locally
$random = Get-Random -Minimum 1111 -Maximum 99999999
$tempProfileXML = "$env:TEMP\tempProfile$random.xml"
$WirelessProfile | Out-File $tempProfileXML
# Add the WiFi profile and connect
Start-Process netsh ('wlan add profile filename={0}' -f $tempProfileXML)
# Connect to the WiFi network - only if you need to
$WifiNetworks = (netsh wlan show network)
$NetworkSSIDSearch = '*' + $NetworkSSID + '*'
If ($WifiNetworks -like $NetworkSSIDSearch) {
Try {
Write-Host "Found SSID: $NetworkSSID `nAttempting to connect"
Start-Process netsh ('wlan connect name="{0}"' -f $NetworkSSID)
Start-Sleep 5
netsh interface show interface
}
Catch {
Remove-Item -Force $tempProfileXML
}
}
Else {
Write-Host "Did not find SSID: $NetworkSSID `nConnection profile stored for later use."
}
Remove-Item -Force $tempProfileXML
}
Function Copy-FolderData {
<#
.SYNOPSIS
Copy source folders and subfolders using robocopy.
.PARAMETER SourcePath
The path of the folder to be copied.
.PARAMETER DestinationPath
The path of the destination to copy to.
.EXAMPLE
Copy-FolderData -SourcePath "C:\SourceData" -DestinationPath "C:\DestinationFolder"
#>
Param (
[Parameter(Mandatory = $True)]
[String] $SourcePath,
[Parameter(Mandatory = $True)]
[String] $DestinationPath
)
# Test if destination exists.
If (-not (Test-Path $DestinationPath)) {
New-Item -Path $DestinationPath -ItemType "directory"
}
# Start robocopy process and pipe to robocopy progress.
Write-Host "Starting Robocopy."
robocopy $SourcePath $DestinationPath /E /NJH /IS /NDL /NC /BYTES
# Copy verification
If ($LASTEXITCODE -le 1) {
Write-Host "Files copied successfully. Exit Code: $LASTEXITCODE" -ForegroundColor Green
}
Else {
Write-Host "Some or all files failed to copy. Exit Code: $LASTEXITCODE" -ForegroundColor Red
}
}
Function Disable-FastStartup {
<#
.SYNOPSIS
Disables Windows Fast Startup by adding/editing the registry and
disabling hibernate via powercfg.
.EXAMPLE
Disable-FastStartup
#>
Write-Host 'Disable Windows Fast Startup' -ForegroundColor Cyan
Try {
REG ADD "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Power" /v HiberbootEnabled /t REG_DWORD /d "0" /f
Write-Host 'Adding registry key.' -ForegroundColor Green
powercfg -hibernate off
Write-Host 'Setting hibernate to off.' -ForegroundColor Green
}
Catch {
Write-Host 'Failed to disable fast startup' -ForegroundColor Red
}
}
Function Enable-SSL {
<#
.SYNOPSIS
Enables SSL within the powershell session.
.EXAMPLE
Enable-SSL
#>
Write-Host "Enabling SSL" -ForegroundColor Cyan
Try {
# Set TLS 1.2 (3072), then TLS 1.1 (768), then TLS 1.0 (192)
# Use integers because the enumeration values for TLS 1.2 and TLS 1.1 won't
# exist in .NET 4.0, even though they are addressable if .NET 4.5+ is
# installed (.NET 4.5 is an in-place upgrade).
[System.Net.ServicePointManager]::SecurityProtocol = 3072 -bor 768 -bor 192
Write-Host 'SSL enabled successfully.' - -ForegroundColor Green
}
Catch {
Write-Host 'Unable to set PowerShell to use TLS 1.2 and TLS 1.1 due to old .NET Framework installed. If you see underlying connection closed or trust errors, you may need to upgrade to .NET Framework 4.5+ and PowerShell v3+.' -ForegroundColor Red
}
}
Function Install-Office365 {
<#
.SYNOPSIS
Installs Office 365 and adds shortcuts to public desktop
.PARAMETER SiteCode
Used to identify the prefix of a customised XML file.
Example: $SiteCode_O365_Config.xml
.PARAMETER DataFolder
The root folder that has the O365 folder with setup.exe and config files.
.EXAMPLE
Install-Office365 -SiteCode "ABC"
#>
Param (
[Parameter(Mandatory = $True)]
[String] $SiteCode
)
Write-Host "Starting Office 365 Installation"
# Installation Variables
$O365ConfigDest = "C:\IT\Software\O365\" + $SiteCode + "_O365_Config.xml"
# Shortcut Variables
$O365Root64 = "C:\Program Files\Microsoft Office\root\Office16\"
$O365Root32 = "C:\Program Files (x86)\Microsoft Office\root\Office16\"
$O365Apps = @{ Word = "WINWORD"; Outlook = "OUTLOOK"; Excel = "EXCEL" }
Write-Host "Installing Office 365"
& C:\IT\Software\O365\setup.exe /configure $O365ConfigDest | Wait-Process
If ((Test-Path $O365Root64) -or (Test-Path $O365Root32)) {
Write-Host "Placing Shortcuts"
ForEach ($App in $O365Apps.Keys) {
# Set Path variables for O365 root
$Path64 = "{0}{1}.exe" -f $O365Root64, $($O365Apps[$App])
$Path32 = "{0}{1}.exe" -f $O365Root32, $($O365Apps[$App])
Try {
# Confirm Office 365 version
If (Test-Path $Path64) {
$TargetFile = $Path64
}
ElseIf (Test-Path $Path32) {
$TargetFile = $Path32
}
# Create the shortcut on public desktop
$ShortcutFile = "$env:Public\Desktop\{0}.lnk" -f $App
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($ShortcutFile)
$Shortcut.TargetPath = $TargetFile
$Shortcut.Save()
Write-Host "Added $App shortcut" -ForegroundColor Green
}
Catch {
Write-Host "Could not place shortcuts" -ForegroundColor Red
}
}
}
Else {
Write-Host "Could not place shortcuts" -ForegroundColor Red
}
}
Function Install-SiteApps {
<#
.SYNOPSIS
Installs Applications from a CSV File.
.PARAMETER CSVPath
The path to the CSV File.
.PARAMETER SiteCode
The site code to install specific software for.
.PARAMETER InstallOther
Install specific software over others as identified in the CSV.
.EXAMPLE
Install-SiteApps -CSVPath "C:\Data\file.csv"
#>
Param (
[Parameter(Mandatory = $True)]
[String] $CSVPath,
[Parameter(Mandatory = $True)]
[String] $SiteCode
)
Begin {
Write-Host "Installing Site Apps"
Write-Host "Importing CSV Data"
If (Test-Path $CSVPath) {
$AppsList = Import-Csv -Path $CSVPath -Delimiter ","
}
}
Process {
If ($AppsList) {
Write-Host "Installing $SiteCode Applications"
ForEach ($App in $AppsList) {
$Application = $App.App
$AppPath = $App.Path + $Application
$MstPath = $App.Path + $App.MST
$Install = $App.Install
If (Test-Path $AppPath) {
If ($Install -eq "Y") {
Write-Host "Installing $Application"
If ($App.MST -eq "") {
$Arguments = @(
"/i",
$AppPath,
"/quiet"
)
Start-Process msiexec.exe -ArgumentList $Arguments -Wait -NoNewWindow
}
ElseIf (-not $App.MST -eq "") {
$Arguments = @(
"/i"
$AppPath,
"TRANSFORMS={0}",
"/quiet"
) -f $MstPath
Start-Process msiexec.exe -ArgumentList $Arguments -Wait -NoNewWindow
}
Else {
Write-Host "Could not install $Application"
}
}
}
}
Write-Host "App Installation Complete"
}
}
}
Function Install-WinGet {
<#
.SYNOPSIS
Installs Microsofts WinGet
.EXAMPLE
Install-WinGet
#>
$progressPreference = 'silentlyContinue'
If (Get-Command winget -ErrorAction SilentlyContinue) {
Write-Host "WinGet is already installed."
}
Else {
Try {
$latestWingetMsixBundleUri = $(Invoke-RestMethod https://api.github.com/repos/microsoft/winget-cli/releases/latest).assets.browser_download_url | Where-Object { $_.EndsWith(".msixbundle") }
$latestWingetMsixBundle = $latestWingetMsixBundleUri.Split("/")[-1]
Write-Information "Downloading winget to artifacts directory..."
Invoke-WebRequest -Uri $latestWingetMsixBundleUri -OutFile "./$latestWingetMsixBundle"
Invoke-WebRequest -Uri https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx -OutFile Microsoft.VCLibs.x64.14.00.Desktop.appx
Add-AppxPackage Microsoft.VCLibs.x64.14.00.Desktop.appx
Add-AppxPackage $latestWingetMsixBundle
}
Catch {
Write-Host "Could not install WinGet"
}
}
}
Function Join-Domain {
<#
.SYNOPSIS
Joins the specified domain with the specified credentials.
.PARAMETER Domain
The domain to join the computer to.
.PARAMETER Username
Username of account with permission to join computers to domains.
.PARAMETER Password
The account password.
.EXAMPLE
Join-Domain -Domain "Example.local" -Username "Administrator" -Password "Password1234"
#>
Param (
[Parameter(Mandatory = $True)]
[String] $Domain,
[Parameter(Mandatory = $True)]
[String] $Username,
[Parameter(Mandatory = $True)]
[String] $Password
)
Write-Host "Join Domain"
$Password = ConvertTo-SecureString $Password -AsPlainText -Force
$Username = $Domain + "\" + $Username
$credential = New-Object System.Management.Automation.PSCredential($Username, $Password)
Try {
Add-Computer -DomainName $Domain -Credential $credential
Write-Host "Successfully joined the $Domain domain." -ForegroundColor Green
}
Catch {
Write-Host "Unable to join the $Domain domain." -ForegroundColor Red
}
}
Function Set-RunOnceScript {
<#
.SYNOPSIS
Sets a script to run on next reboot.
.PARAMETER Label
Name the registry key
.PARAMETER Script
The path to the script to run.
.EXAMPLE
Set-RunOnceScript -Label "Pass2" -Script "C:\IT\Script2.ps1"
#>
Param (
[Parameter(Mandatory = $True)]
[String]$Label,
[Parameter(Mandatory = $True)]
[String]$Script
)
Begin {
Write-Host "Setting run-once script."
$RunOnceValue = 'PowerShell.exe -ExecutionPolicy Bypass -File "' + $Script + '"'
}
Process {
Set-ItemProperty 'HKLM:\Software\Microsoft\Windows\CurrentVersion\RunOnce' -Name $Label -Value $RunOnceValue
Write-Host "Run-once script set"
}
}
Function Set-AutoLogon {
<#
.SYNOPSIS
Sets an admin account to autologon after the next reboot.
.PARAMETER DefaultUsername
The temporary local admin username
.PARAMETER DefaultPassword
The temporary local admin password
.EXAMPLE
Set-AutoLogon -DefaultUsername "TempUser" -DefaultPassword "TempPass"
#>
Param (
[Parameter(Mandatory = $False)]
[String] $DefaultUsername,
[Parameter(Mandatory = $False)]
[String] $DefaultPassword
)
Write-Host "Set autologon"
#Registry path declaration
$RegPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
#setting registry values
Set-ItemProperty $RegPath "AutoAdminLogon" -Value "1" -type String
Set-ItemProperty $RegPath "DefaultUsername" -Value $DefaultUsername -type String
Set-ItemProperty $RegPath "DefaultPassword" -Value $DefaultPassword -type String
Set-ItemProperty $RegPath "AutoLogonCount" -Value "1" -type DWord
Write-Host "End of Set autologon"
}
Function Set-DailyReboot {
<#
.SYNOPSIS
Creates a scheduled task to restart the computer daily at 3am, if no one is using the computer.
Helpful for maintaining updated and stability.
.EXAMPLE
Set-DailyReboot
#>
Begin {
Write-Host "Schedule Daily Restart"
$Action = New-ScheduledTaskAction -Execute 'shutdown.exe' -Argument '-f -r -t 0'
$Trigger = New-ScheduledTaskTrigger -Daily -At 3am
$Idle = New-ScheduledTaskSettingsSet -RunOnlyIfIdle -IdleDuration 00:30:00 -IdleWaitTimeout 02:00:00
$User = "NT AUTHORITY\SYSTEM"
}
Process {
Register-ScheduledTask -Action $action -Trigger $trigger -User $User -Settings $Idle -TaskName "Daily Restart" -Description "Daily restart" -Force | Out-Null
$NewDate = (Get-ScheduledTask -TaskName "Daily Restart").Triggers.StartBoundary.subString(0, 16)
Write-Host "The next scheduled 'Daily Restart' task will happen at $([Datetime]::ParseExact($NewDate, 'yyyy-MM-ddTHH:mm', $null))"
}
}
Function Set-GMTTime {
<#
.SYNOPSIS
Sets the system timezone to GMT
.EXAMPLE
Set-GMTTime
#>
Process {
Write-Host "Setting timezone to GMT"
Set-TimeZone -Name "GMT Standard Time"
}
End {
net start W32Time
W32tm /resync /force
}
}
Function Set-NumLock {
<#
.SYNOPSIS
Sets numlock to on by default
.EXAMPLE
Set-NumLock
#>
Process {
Write-Host "Setting Numlock as default"
Set-ItemProperty -Path 'Registry::HKU\.DEFAULT\Control Panel\Keyboard' -Name "InitialKeyboardIndicators" -Value "2" -Force -PassThru
}
}
Function Start-Win10Decrapify {
<#
.SYNOPSIS
Runs Windows 10 Decrapifier by CSAND.
Version in Sentinel-Functions GitHub is modified to set a few switches to true.
.LINK
https://community.spiceworks.com/scripts/show/4378-windows-10-decrapifier-18xx-19xx-2xxx
.PARAMETER ScriptURL
URL to raw script file.
.EXAMPLE
Start-Win10Decrapify -ScriptURL "https://example.com/script"
#>
Param (
[Parameter(Mandatory = $True)]
[String] $ScriptURL
)
Begin {
Write-Host "Starting Windows 10 Decrapifier"
Set-ExecutionPolicy Bypass -Scope Process -Force
Enable-SSL
}
Process { Invoke-WebRequest $ScriptURL -UseBasicParsing | Invoke-Expression }
}
Function Start-PPKGLog {
<#
.SYNOPSIS
Starts a transcript with a specific name.
.PARAMETER LogLabel
A short string for the log title
.PARAMETER SiteCode
The unique code for the site.
.EXAMPLE
Start-PPKGLog -LogLabel "Pass1" -SiteCode "ABC"
#>
Param (
[Parameter(Mandatory = $True)]
[String] $LogLabel,
[Parameter(Mandatory = $False)]
[String] $SiteCode
)
Write-Host "Creating Log File"
$LogPath = "C:\IT\" + $SiteCode + "-" + $LogLabel + ".log"
Start-Transcript -Path $LogPath -Force -Append
}
Function Update-DellPackages {
<#
.SYNOPSIS
Uses the CLI version of Dell Command | Update to install any missing drivers/firmwares/Bios and update existing ones.
There are no parameters to use.
.LINK
https://www.dell.com/support/kbdoc/en-us/000177325/dell-command-update
.EXAMPLE
Update-DellPackages
#>
Function Install-DCU {
#Install the latest version
Stop-Process -Name DellCommandUpdate -Force -ErrorAction SilentlyContinue
winget install Dell.CommandUpdate.Universal --force --accept-source-agreements --accept-package-agreements
}
Write-Host "Dell Updates"
$Manufacturer = (Get-CimInstance -Class Win32_ComputerSystem).Manufacturer
If ( $Manufacturer -like "*Dell*") {
If (Get-Command winget) {
Write-Host "Updating App Installer"
winget upgrade "App Installer" --accept-source-agreements --accept-package-agreements
}
Else {
Install-WinGet
}
Write-Host "Checking if 'Dell Command Update' is current."
#Remove any Windows 10 "Apps"
Get-ProvisionedAppPackage -Online -ErrorAction SilentlyContinue | Where-Object { $_.DisplayName -like "*Dell*Update*" } | Remove-ProvisionedAppPackage -Online
Get-AppxPackage "*Dell*Update*" -ErrorAction SilentlyContinue | Remove-AppxPackage
Get-Package "Dell*Windows 10" -ErrorAction SilentlyContinue | Uninstall-Package -AllVersions -Force
If (Get-AppxPackage *Dell*Update*) {
$apps = Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall | Get-ItemProperty | Where-Object { $_.DisplayName -like "Dell*Update*" } | Select-Object -Property DisplayName, UninstallString
ForEach ($ver in $apps) {
If ($ver.UninstallString) {
$uninst = $ver.UninstallString
Write-Host Uninstalling: $ver.DisplayName
Start-Process cmd -ArgumentList "/c $uninst /quiet /norestart" -NoNewWindow -Wait -PassThru
}
}
}
#Compare version numbers of any remaining installed version.
$DCUInstalledVersion = (Get-Package -Provider Programs -IncludeWindowsInstaller -Name "Dell Command | Update" -ErrorAction SilentlyContinue).Version
$DCUAvailableVersion = winget show Dell.CommandUpdate.Universal #Gets all results
$DCUAvailableVersion = ($DCUAvailableVersion | Select-String -Pattern "Version: " -SimpleMatch).Line
$DCUAvailableVersion = $DCUAvailableVersion.split(" ", [System.StringSplitOptions]::RemoveEmptyEntries)[1]
If (-not $DCUInstalledVersion) {
Write-Host "'Dell Command Update' is not installed, installing now."
Install-DCU
}
ElseIf ($DCUInstalledVersion -ne $DCUAvailableVersion) {
Write-Host "'Dell Command Update' is not current. Updating from version $DCUInstalledVersion to $DCUAvailableVersion."
#Remove any programs listed through "Add and remove programs"
$DCUInstalled = Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -like "*Dell*Update*" }
If ($DCUInstalled) {
$DCUInstalled.Uninstall()
}
Install-DCU
}
ElseIf ($DCUInstalledVersion -eq $DCUAvailableVersion) {
Write-Host "'Dell Command Update' is current."
}
#Configure and run Dell Command Update
Stop-Process -Name DellCommandUpdate -Force -ErrorAction SilentlyContinue
$DCUx86 = Join-Path -Path ${env:ProgramFiles(x86)} -ChildPath "Dell\CommandUpdate\dcu-cli.exe"
$DCUx64 = Join-Path -Path $Env:ProgramFiles -ChildPath "Dell\CommandUpdate\dcu-cli.exe"
If (Test-Path $DCUx86) {
& $DCUx86 /configure -silent -autoSuspendBitLocker=enable -userConsent=disable -scheduleManual
& $DCUx86 /applyUpdates -reboot=disable
}
ElseIf (Test-Path $DCUx64) {
& $DCUx64 /configure -silent -autoSuspendBitLocker=enable -userConsent=disable -scheduleManual
& $DCUx64 /applyUpdates -reboot=disable
}
Else { Write-Error "Dell Command Update CLI not found." }
}
Else { Write-Host "This is not a Dell Computer" }
Write-Host "`n> End of Dell Updates"
}
Function Update-Windows {
<#
.SYNOPSIS
Function to update windows.
.LINK
https://raw.githubusercontent.com/AmbitionsTechnologyGroup/ATG-PS-Functions/master/Scripts/Windows-Update/UpdateWindows.txt
.PARAMETER NoSofware
Set whether to exclude software during windows update.
Set to false to exclude software.
.PARAMETER NoDrivers
Set whether to exclude drivers during windows update.
Set to false to exclude drivers.
.EXAMPLE
Update-Windows -NoDrivers $False
#>
Param (
[Parameter(Mandatory = $False)]
[Switch] $NoSofware,
[Parameter(Mandatory = $False)]
[Switch] $NoDrivers
)
Begin {
Write-Host "Windows Updates"
Set-ExecutionPolicy Bypass -Scope Process -Force
$WUService = Get-Service wuauserv
# Start Windows Update service if stopped
if (!($WUService.Status -eq "Stopped")) {
Write-Host "Starting the Windows update Service | Waiting for 10 seconds..."
Start-Service wuauserv
Start-Sleep -Seconds 10
}
}
Process {
Write-Host "Installing Windows Updates"
Function RegisterWindowsUpdates {
Write-Host "Checking Microsoft Update Service"
If ((Get-WUServiceManager).Name -like "Microsoft Update") {
Write-Host "Microsoft Update Service found, it's good to go."
}
else {
Write-Host "Microsoft Update Service not found, registering it."
Add-WUServiceManager -ServiceID 7971f918-a847-4430-9279-4a52d1efe18d -Confirm:$false
}
}
Write-Host "Checking WinGet Installation"
# Check if WinGet already installed
If (-not (Get-AppxPackage *DesktopAppInstaller*)) {
# Install WinGet
Write-Host "WinGet is not installed. Installing WinGet."
Add-AppxPackage -RegisterByFamilyName -MainPackage Microsoft.DesktopAppInstaller_8wekyb3d8bbwe
Write-Host "Installed Microsoft App Installer" -ForegroundColor Green
}
Write-Host "Checking PowerShell version."
If ($PSVersionTable.PSVersion.Major -lt "5") {
Write-Host "Powershell needs an update, installing now"
winget install --id Microsoft.Powershell --source winget --accept-source-agreements --accept-package-agreements
Write-Host "Reboot computer and run script again"
}
Else {
If ((Get-Command Get-WUInstall -ErrorAction SilentlyContinue) -And ((Get-Command Get-WUInstall -ErrorAction SilentlyContinue).Version.Major -lt "2")) {
$Module = Get-Module -Name PSWindowsUpdate
Write-Host "Removing an out of date PSWindowsUpdate"
Uninstall-Module $Module.Name
Remove-Module $Module.Name
Remove-Item $Module.ModuleBase -Recurse -Force
}
If (-Not (((Get-Command Get-WUInstall -ErrorAction SilentlyContinue).Version.Major -ge "2") -and ((Get-Command Get-WUInstall -ErrorAction SilentlyContinue).Version.Minor -ge "1"))) {
Write-Host "Attempting automatic installation of PSWUI 2.2.0.2"
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.208 -Force -ErrorAction SilentlyContinue
Install-Module -Name PSWindowsUpdate -MinimumVersion 2.2.0.2 -Force -ErrorAction SilentlyContinue
RegisterWindowsUpdates
If (-Not (((Get-Command Get-WUInstall -ErrorAction SilentlyContinue).Version.Major -ge "2") -and ((Get-Command Get-WUInstall -ErrorAction SilentlyContinue).Version.Minor -ge "1"))) {
Write-Host "Auto install Failed, Attempting Manual installation of PSWUI 2.2.0.2"
New-Item -ItemType Directory -Force -Path 'C:\IT' -ErrorAction Stop
(New-Object System.Net.WebClient).DownloadFile('https://psg-prod-eastus.azureedge.net/packages/pswindowsupdate.2.2.0.2.nupkg', 'C:\IT\pswindowsupdate.2.2.0.2.zip')
New-Item -ItemType Directory -Force -Path 'C:\Windows\System32\WindowsPowerShell\v1.0\Modules\PSWindowsUpdate\2.2.0.2' -ErrorAction Stop
Expand-Archive -LiteralPath 'C:\IT\pswindowsupdate.2.2.0.2.zip' -DestinationPath 'C:\Windows\System32\WindowsPowerShell\v1.0\Modules\PSWindowsUpdate\2.2.0.2' -ErrorAction Stop
Import-Module PSWindowsUpdate -ErrorAction Stop
RegisterWindowsUpdates
}
}
If (((Get-Command Get-WUInstall -ErrorAction SilentlyContinue).Version.Major -ge "2") -and ((Get-Command Get-WUInstall -ErrorAction SilentlyContinue).Version.Minor -ge "1")) {
Write-Host "PSWindowsUpdate is installed"
If ($NoDrivers -ne $True) {
Write-Host "Checking for DRIVER Updates..."
Get-WUInstall -MicrosoftUpdate -AcceptAll -Install -UpdateType Driver -IgnoreReboot -ErrorAction SilentlyContinue -Verbose
}
If ($NoSoftware -ne $True) {
Write-Host "Checking for SOFTWARE Updates..."
Get-WUInstall -MicrosoftUpdate -AcceptAll -Install -UpdateType Software -IgnoreReboot -ErrorAction SilentlyContinue -Verbose
}
}
Else {
Write-Host "PSWindowsUpdate is failing to install, please investigate" -ForegroundColor Red
}
}
Write-Host "End of Install Windows Updates"
}
}
Function Update-WindowsApps {
<#
.SYNOPSIS
Launches Microsoft Store and updates installed apps.
.EXAMPLE
Update-WindowsApps
#>
Begin {
Write-Host "Updating Windows Apps"
Start-Process ms-windows-store:
Start-Sleep -Seconds 5
}
Process {
(Get-WmiObject -Namespace "root\cimv2\mdm\dmmap" -Class "MDM_EnterpriseModernAppManagement_AppManagement01").UpdateScanMethod()
Write-Host "Update Windows Apps initiated"
}
}
Function Update-WindowTitle {
<#
.SYNOPSIS
Sets the title of the window to a custom string.
.PARAMETER PassNumber
The script number, first script would be 1.
.PARAMETER SiteCode
The unique code for the site.
.EXAMPLE
Update-WindowTitle -PassNumber "1" -SiteCode "ABC"
#>
Param (
[Parameter(Mandatory = $True)]
[String] $PassNumber,
[Parameter(Mandatory = $False)]
[String] $SiteCode
)
Write-Host "Changing window title"
$host.ui.RawUI.WindowTitle = "$SiteCode Provisioning | $env:computername | Pass $PassNumber | Please Wait"
}