From 82815d411616c7a2787100b4ae0b9c0da54d2503 Mon Sep 17 00:00:00 2001 From: Upgrayedd Date: Wed, 21 Aug 2024 19:20:11 -0500 Subject: [PATCH] Update Windows/PSPatching.ps1 Got Good -er was just the bones before, now its got *logic* --- Windows/PSPatching.ps1 | 55 ++++++++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 13 deletions(-) diff --git a/Windows/PSPatching.ps1 b/Windows/PSPatching.ps1 index 59720cf..f20d22e 100644 --- a/Windows/PSPatching.ps1 +++ b/Windows/PSPatching.ps1 @@ -1,17 +1,46 @@ -[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 -Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force -Install-Module PSWindowsUpdate -Force -Set-ExecutionPolicy bypass -Import-Module PSWindowsUpdate +#for old windows, 8/2012r2, check to come +#[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 + +#module logic +if (Get-Module -ListAvailable -Name PSWindowsUpdate) { + Import-Module PSWindowsUpdate + Write-Host "On it" +} +else { + Write-Host "Haven't been here before, give me a min" + Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force + Install-Module PSWindowsUpdate -Force + +} + +#do we even need updates? +$updates = Get-WUList -verbose +if ($updates.Contains("Found [0] Updates")){ + Write-Host "No Updates" + +} +else { + Write-Host "Updates are `n" $updates.Title +} + +#time logic +$now = Get-Date +$WorkHours = $now.Hour -in 8..17 -Get-WUList -verbose +if (!$WorkHours) { + Install-WindowsUpdate -AcceptAll -ignorereboot | Out-File "C:\Windows\Temp\$(get-date -f yyyy-MM-dd)-WindowsUpdate.log" -force +} +else { +#scheduled task creation goes here + Write-Host "Its still during operating hours, do me again later" +} -Install-WindowsUpdate -AcceptAll -ignorereboot | Out-File "C:\Windows\Temp\$(get-date -f yyyy-MM-dd)-WindowsUpdate.log" -force - -Get-WURebootStatus -silent - - -$tonight = (Get-Date -Hour 23) -Get-WURebootStatus -ScheduleReboot $tonight | select RebootScheduled \ No newline at end of file +if (Get-WURebootStatus -silent) { + $tonight = (Get-Date -Hour 23) + Get-WURebootStatus -ScheduleReboot $tonight | select RebootScheduled +} +else { + Write-Host "Updates installed without reboot required" +} \ No newline at end of file