46 lines
1.1 KiB
PowerShell
46 lines
1.1 KiB
PowerShell
#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
|
|
|
|
|
|
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"
|
|
}
|
|
|
|
|
|
if (Get-WURebootStatus -silent) {
|
|
$tonight = (Get-Date -Hour 23)
|
|
Get-WURebootStatus -ScheduleReboot $tonight | select RebootScheduled
|
|
}
|
|
else {
|
|
Write-Host "Updates installed without reboot required"
|
|
} |