Skip to content

Commit

Permalink
Revert scheduled jobs back to scheduled tasks (#1833)
Browse files Browse the repository at this point in the history
  • Loading branch information
ScriptAutomate authored Oct 3, 2023
1 parent 8c4b286 commit dc6ec59
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
15 changes: 11 additions & 4 deletions os-images/AWS/windows/scripts/InstallAndConfigureOpenSSH.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ Write-Host "EC2 Instance Public Key Written To $openSSHAuthorizedKeys"
# Ensure access control on administrators_authorized_keys meets the requirements
Write-Host "Repairing permissions on $openSSHAuthorizedKeys"
Repair-AdministratorsAuthorizedKeysPermission -FilePath $openSSHAuthorizedKeys -Confirm:$false
Disable-ScheduledTask -TaskName "Download EC2 PubKey"
'@
$keyDownloadScript | Out-File $DOWNLOAD_KEYS_SCRIPT

Expand All @@ -188,10 +190,15 @@ $principal = New-ScheduledTaskPrincipal `
-UserID "NT AUTHORITY\SYSTEM" `
-LogonType ServiceAccount `
-RunLevel Highest
$jobtrigger = New-JobTrigger -AtStartup
$joboptions = New-ScheduledJobOption -RunElevated
Register-ScheduledJob -Name $taskName -Trigger $jobtrigger -FilePath "$DOWNLOAD_KEYS_SCRIPT" -ScheduledJobOption $joboptions
Set-ScheduledTask -TaskName $taskName -Principal $principal
$action = New-ScheduledTaskAction -Execute 'Powershell.exe' `
-Argument "-NoProfile -File ""$DOWNLOAD_KEYS_SCRIPT"" -Verbose > c:\download-ec2-pubkey.log"
$trigger = New-ScheduledTaskTrigger -AtStartup
Register-ScheduledTask -Action $action `
-Trigger $trigger `
-Principal $principal `
-TaskName $taskName `
-Description $taskName
Disable-ScheduledTask -TaskName $taskName

# Run the download keys script, terminate if it fails
& Powershell.exe -ExecutionPolicy Bypass -File $DOWNLOAD_KEYS_SCRIPT
Expand Down
4 changes: 2 additions & 2 deletions os-images/AWS/windows/scripts/SysPrep.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ ElseIf (Test-Path $EC2ConfigDir) {
Else {
throw("Neither $EC2LaunchDir nor $EC2ConfigDir nor $EC2WindowsLaunch were found")
}
Enable-ScheduledJob "Download EC2 PubKey"
Get-ScheduledJob | where state -eq 'Ready'
Enable-ScheduledTask "Download EC2 PubKey"
Get-ScheduledTask | where state -eq 'Ready'

0 comments on commit dc6ec59

Please sign in to comment.