commit cc7fbda41887e997a061bfb82edd0f350a578817 Author: Ivo Oskamp Date: Fri Dec 20 22:15:21 2024 +0100 Upload files to "/" diff --git a/Automatic-updates.ps1 b/Automatic-updates.ps1 new file mode 100644 index 0000000..dfd6499 --- /dev/null +++ b/Automatic-updates.ps1 @@ -0,0 +1,31 @@ +$AvailableUpdates = $null; +$AvailableUpdates = get-wulist; +New-Item -Name updates.csv -ItemType File +If ($null -ne $AvailableUpdates) +{ +#$AvailableUpdates; +set-location C:\scripts\automatic-updates\ +#Remove existing task that will open this script +C:\scripts\automatic-updates\run_from_script\Delete-task.ps1 +#Create task to open Check-updates.ps1 after reboot +C:\scripts\automatic-updates\run_from_script\Create-task-reboot.ps1 +#Create or append csv file with available updates +C:\scripts\automatic-updates\run_from_script\Check-Updates-csv.ps1 +#Install available updates and reboot +C:\scripts\automatic-updates\run_from_script\Install-updates.ps1 +} +Else +{ +Write-Host "No updates found"; +#Remove existing task that will open this script +C:\scripts\automatic-updates\run_from_script\Delete-task.ps1 +#Send mail that there are no updates available +#C:\scripts\automatic-updates\run_from_script\No-updates.ps1 #(If no updates are found this will be send from send-mail-attachment.ps1) +#Send mail with csv file with all updates installed +C:\scripts\automatic-updates\run_from_script\Send-mail-attachment.ps1 +#delete csv file +set-location C:\scripts\automatic-updates\ +Remove-Item updates.csv +#start updates other servers +C:\scripts\automatic-updates\run_from_script\Start-Remote-task.ps1 +} \ No newline at end of file diff --git a/Check-Updates-csv.ps1 b/Check-Updates-csv.ps1 new file mode 100644 index 0000000..55d4c50 --- /dev/null +++ b/Check-Updates-csv.ps1 @@ -0,0 +1,2 @@ +set-location C:\scripts\automatic-updates\ +(Get-WindowsUpdate) | Export-Csv updates.csv -append \ No newline at end of file diff --git a/Create-task-reboot.ps1 b/Create-task-reboot.ps1 new file mode 100644 index 0000000..25c4aa7 --- /dev/null +++ b/Create-task-reboot.ps1 @@ -0,0 +1,22 @@ +#Load variables +. "C:\scripts\automatic-updates-static\Variables.ps1" + +#Create password file with user that will be used for the task +$taskName = 'ContinueAfterBoot' +$user = $taskusername +$SecPassword = Get-Content "c:\scripts\automatic-updates-static\localpassword.txt" | ConvertTo-SecureString +$creds = New-Object System.Management.Automation.PSCredential ($taskusername, $SecPassword) +$Password = $creds.GetNetworkCredential().Password +$trigger = New-ScheduledTaskTrigger -AtStartup +$action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-NoProfile -File C:\Scripts\automatic-updates\Automatic-updates.ps1" + +Register-ScheduledTask ` + -TaskName $taskName ` + -User $taskusername ` + -Password $Password ` + -Action $action ` + -Trigger $trigger ` + -RunLevel Highest -Force + +#Clear password because not encrypted +$Password = "wwreset" diff --git a/Delete-task.ps1 b/Delete-task.ps1 new file mode 100644 index 0000000..840a6cf --- /dev/null +++ b/Delete-task.ps1 @@ -0,0 +1,3 @@ +if(Get-ScheduledTask -TaskName "ContinueAfterBoot" -ErrorAction Ignore){ + Unregister-ScheduledTask -TaskName "ContinueAfterBoot" -Confirm:$false | Out-Null +} \ No newline at end of file diff --git a/automatic-updates-v2-main.zip b/automatic-updates-v2-main.zip new file mode 100644 index 0000000..e3f9bf4 Binary files /dev/null and b/automatic-updates-v2-main.zip differ