Update Utility Scripts/Windows Upgrade Prep.ps1

This commit is contained in:
2025-08-05 14:47:26 +00:00
parent 305001f79e
commit 9deaa50985
+133 -134
View File
@@ -1,135 +1,134 @@
<# <#
Author: Gabe Kerntke Author: Gabe Kerntke
Company: UFS LLC Date: 02-13-2025
Date: 02-13-2025
.Synopsis
.Synopsis
.Modified
.Modified 2025-02-13 (GabeK) - Original script created
2025-02-13 (GabeK) - Original script created 2025-06-24 (GabeK) - Script updated to fix bugs and use functions script
2025-06-24 (GabeK) - Script updated to fix bugs and use functions script #>
#>
[CmdletBinding()]
[CmdletBinding()] Param(
Param( [Parameter(Mandatory = $false)]
[Parameter(Mandatory = $false)] $App_Name = "WindowsPCHealthCheckSetup",
$App_Name = "WindowsPCHealthCheckSetup", [Parameter(Mandatory = $false)]
[Parameter(Mandatory = $false)] $File_Name_Extension = "msi",
$File_Name_Extension = "msi", [Parameter(Mandatory = $false)]
[Parameter(Mandatory = $false)] $Install_Parameters = "/qn",
$Install_Parameters = "/qn", [Parameter(Mandatory = $false)]
[Parameter(Mandatory = $false)] $EPCache_Folder = "3rd Party Patches\$App_Name",
$EPCache_Folder = "3rd Party Patches\$App_Name", [Parameter(Mandatory = $false)]
[Parameter(Mandatory = $false)] $DownloadURL = "https://aka.ms/GetPCHealthCheckApp",
$DownloadURL = "https://aka.ms/GetPCHealthCheckApp", [Parameter(Mandatory = $false)]
[Parameter(Mandatory = $false)] $File_Name = "$App_Name.$File_Name_Extension"
$File_Name = "$App_Name.$File_Name_Extension" )
)
#Region Functions
#Region Functions
Function Start-DiskCleanup {
Function Start-DiskCleanup { $Size = Get-PSDrive C | Select-Object -ExpandProperty Free
$Size = Get-PSDrive C | Select-Object -ExpandProperty Free
Function Remove-Windows_Updates_Cache {
Function Remove-Windows_Updates_Cache { #Stops services related to Windows Updates
#Stops services related to Windows Updates Stop-Service wuauserv
Stop-Service wuauserv Stop-Service BITS
Stop-Service BITS Start-Sleep 30
Start-Sleep 30
#Cleans out the Windows Updates patch cache folder
#Cleans out the Windows Updates patch cache folder Get-ChildItem "C:\Windows\SoftwareDistribution\Download\" | Remove-Item -Force -Recurse
Get-ChildItem "C:\Windows\SoftwareDistribution\Download\" | Remove-Item -Force -Recurse Start-Sleep 30
Start-Sleep 30
#Starts the services
#Starts the services Start-Service wuauserv
Start-Service wuauserv Start-Service BITS
Start-Service BITS Start-Sleep 15
Start-Sleep 15 }
}
#Check free space after running script
#Check free space after running script Function Convert-Size {
Function Convert-Size { switch ($Size) {
switch ($Size) { { $_ -gt 1TB } { ($Size / 1TB).ToString("n2") + " TB"; break }
{ $_ -gt 1TB } { ($Size / 1TB).ToString("n2") + " TB"; break } { $_ -gt 1GB } { ($Size / 1GB).ToString("n2") + " GB"; break }
{ $_ -gt 1GB } { ($Size / 1GB).ToString("n2") + " GB"; break } { $_ -gt 1MB } { ($Size / 1MB).ToString("n2") + " MB"; break }
{ $_ -gt 1MB } { ($Size / 1MB).ToString("n2") + " MB"; break } { $_ -gt 1KB } { ($Size / 1KB).ToString("n2") + " KB"; break }
{ $_ -gt 1KB } { ($Size / 1KB).ToString("n2") + " KB"; break } default { "$Size B" }
default { "$Size B" } }
} }
}
# Script Start
# Script Start
If ((Test-Path "C:\Temp\Script Cache") -eq $False) { New-Item -ItemType directory -Path "C:\Temp\Script Cache" }
If ((Test-Path "C:\Temp\Script Cache") -eq $False) { New-Item -ItemType directory -Path "C:\Temp\Script Cache" } Invoke-WebRequest -UseBasicParsing "https://scripts.gabesville.com/Gabesville/Powershell-Scripts/raw/branch/main/Functions%20Scripts/Functions.ps1" -outfile "C:\Temp\Script Cache\Functions.ps1"
Invoke-WebRequest -UseBasicParsing "https://scripts.gabesville.com/Gabesville/Powershell-Scripts/raw/branch/main/Functions%20Scripts/Functions.ps1" -outfile "C:\Temp\Script Cache\Functions.ps1" . "C:\Temp\Script Cache\Functions.ps1"
. "C:\Temp\Script Cache\Functions.ps1"
#Calculate starting free space
#Calculate starting free space [INT64]$StartFreeSpace = (Get-WmiObject -Class Win32_logicaldisk | Where-Object { $_.DeviceID -eq 'C:' }).Freespace
[INT64]$StartFreeSpace = (Get-WmiObject -Class Win32_logicaldisk | Where-Object { $_.DeviceID -eq 'C:' }).Freespace
#Check to see if program is installed
#Check to see if program is installed $Applist = Get-Software | Sort-Object -Descending
$Applist = Get-Software | Sort-Object -Descending
If ($Applist.DisplayName -like "*$App_Name*") {
If ($Applist.DisplayName -like "*$App_Name*") { Remove-Probe_Cache
Remove-Probe_Cache }
} Remove-Agent_Cache
Remove-Agent_Cache Start-Disk_Cleanup
Start-Disk_Cleanup Remove-Windows_Updates_Cache
Remove-Windows_Updates_Cache
#Calculate space freed up and report out
#Calculate space freed up and report out [INT64]$EndFreeSpace = (Get-WmiObject -Class Win32_logicaldisk | Where { $_.DeviceID -eq 'C:' }).Freespace
[INT64]$EndFreeSpace = (Get-WmiObject -Class Win32_logicaldisk | Where { $_.DeviceID -eq 'C:' }).Freespace $SpaceFreed = "{0:N2}" -f (($EndFreeSpace - $StartFreeSpace) / 1GB)
$SpaceFreed = "{0:N2}" -f (($EndFreeSpace - $StartFreeSpace) / 1GB) Write-Output "Space freed up: $($SpaceFreed)GB"
Write-Output "Space freed up: $($SpaceFreed)GB" $FreeAfter = Convert-Size
$FreeAfter = Convert-Size Write-Host "$FreeAfter space free on C drive"
Write-Host "$FreeAfter space free on C drive" }
}
Function Start-PCHealthCheck {
Function Start-PCHealthCheck {
Function Set-RegKeys {
Function Set-RegKeys { New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS
New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS Start-Sleep 5
Start-Sleep 5
$GetPaths = Get-ChildItem "HKU:\" -ErrorAction SilentlyContinue | Select-Object -Skip 1 -ExpandProperty Name
$GetPaths = Get-ChildItem "HKU:\" -ErrorAction SilentlyContinue | Select-Object -Skip 1 -ExpandProperty Name $RegPaths = $GetPaths.replace('HKEY_USERS\', '')
$RegPaths = $GetPaths.replace('HKEY_USERS\', '') $Location = foreach ($Path in $RegPaths) {
$Location = foreach ($Path in $RegPaths) { Get-ChildItem "HKU:\$Path\Software\Microsoft" -Recurse -ErrorAction SilentlyContinue | Where-Object { $_.Name -like "*PCHC*" } | Select-Object -ExpandProperty PSPath
Get-ChildItem "HKU:\$Path\Software\Microsoft" -Recurse -ErrorAction SilentlyContinue | Where-Object { $_.Name -like "*PCHC*" } | Select-Object -ExpandProperty PSPath Get-ChildItem "HKU:\$Path\Software\Microsoft" -Recurse -ErrorAction SilentlyContinue | Where-Object { $_.Name -like "*PCHealthCheck*" } | Select-Object -ExpandProperty PSPath
Get-ChildItem "HKU:\$Path\Software\Microsoft" -Recurse -ErrorAction SilentlyContinue | Where-Object { $_.Name -like "*PCHealthCheck*" } | Select-Object -ExpandProperty PSPath }
} New-ItemProperty -Path $Location.substring(26) -Name "UpgradeEligibility" -Value 1 -Type DWORD -Force -Verbose
New-ItemProperty -Path $Location.substring(26) -Name "UpgradeEligibility" -Value 1 -Type DWORD -Force -Verbose }
}
# Start Script #
# Start Script #
#Use TLS 1.2 for communication
#Use TLS 1.2 for communication [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 If ((Test-Path "C:\Temp\Script Cache") -eq $False) { New-Item -ItemType directory -Path "C:\Temp\Script Cache" }
If ((Test-Path "C:\Temp\Script Cache") -eq $False) { New-Item -ItemType directory -Path "C:\Temp\Script Cache" } Invoke-WebRequest -UseBasicParsing "https://scripts.gabesville.com/Gabesville/Powershell-Scripts/raw/branch/main/Functions%20Scripts/Functions.ps1" -outfile "C:\Temp\Script Cache\Functions.ps1"
Invoke-WebRequest -UseBasicParsing "https://scripts.gabesville.com/Gabesville/Powershell-Scripts/raw/branch/main/Functions%20Scripts/Functions.ps1" -outfile "C:\Temp\Script Cache\Functions.ps1" . "C:\Temp\Script Cache\Functions.ps1"
. "C:\Temp\Script Cache\Functions.ps1"
#Check if App is installed
#Check if App is installed $Applist = Get-Software | Sort-Object -Descending
$Applist = Get-Software | Sort-Object -Descending Start-Sleep 5
Start-Sleep 5
If ($Applist.DisplayName -notlike "*$App_Name*") {
If ($Applist.DisplayName -notlike "*$App_Name*") { Test-Probe_Online
Test-Probe_Online Install-App
Install-App Set-RegKeys
Set-RegKeys }
} Else {
Else { Write-Host "$Name is installed, exiting script."
Write-Host "$Name is installed, exiting script." Set-RegKeys
Set-RegKeys }
} }
}
#Region Script Start
#Region Script Start Start-PCHealthCheck
Start-PCHealthCheck Start-DiskCleanup
Start-DiskCleanup Start-Sleep 900
Start-Sleep 900 $BLinfo = Get-Bitlockervolume
$BLinfo = Get-Bitlockervolume If ($blinfo.ProtectionStatus -eq 'On' -and $blinfo.EncryptionPercentage -eq '100') {
If ($blinfo.ProtectionStatus -eq 'On' -and $blinfo.EncryptionPercentage -eq '100') { Manage-bde -Protectors -Disable C: -RebootCount 5
Manage-bde -Protectors -Disable C: -RebootCount 5 }
} Restart-Computer -Force
Restart-Computer -Force
#Region Script End #Region Script End