Upload files to "/"

This commit is contained in:
Ivo Oskamp 2024-12-20 22:15:21 +01:00
commit cc7fbda418
5 changed files with 58 additions and 0 deletions

31
Automatic-updates.ps1 Normal file
View File

@ -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
}

2
Check-Updates-csv.ps1 Normal file
View File

@ -0,0 +1,2 @@
set-location C:\scripts\automatic-updates\
(Get-WindowsUpdate) | Export-Csv updates.csv -append

22
Create-task-reboot.ps1 Normal file
View File

@ -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"

3
Delete-task.ps1 Normal file
View File

@ -0,0 +1,3 @@
if(Get-ScheduledTask -TaskName "ContinueAfterBoot" -ErrorAction Ignore){
Unregister-ScheduledTask -TaskName "ContinueAfterBoot" -Confirm:$false | Out-Null
}

Binary file not shown.