diff --git a/azure_jumpstart_arcbox/artifacts/Bootstrap.ps1 b/azure_jumpstart_arcbox/artifacts/Bootstrap.ps1 index aef8f25be6..1755812d5e 100644 --- a/azure_jumpstart_arcbox/artifacts/Bootstrap.ps1 +++ b/azure_jumpstart_arcbox/artifacts/Bootstrap.ps1 @@ -117,6 +117,9 @@ if ([bool]$vmAutologon) { } } +# Set SyncForegroundPolicy to 1 to ensure that the scheduled task runs after the client VM joins the domain +Set-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" "SyncForegroundPolicy" 1 + # Copy PowerShell Profile and Reload Invoke-WebRequest ($templateBaseUrl + "artifacts/PSProfile.ps1") -OutFile $PsHome\Profile.ps1 .$PsHome\Profile.ps1 diff --git a/azure_jumpstart_arcbox/artifacts/RunAfterClientVMADJoin.ps1 b/azure_jumpstart_arcbox/artifacts/RunAfterClientVMADJoin.ps1 index 5cd2fea19a..d5fc03124a 100644 --- a/azure_jumpstart_arcbox/artifacts/RunAfterClientVMADJoin.ps1 +++ b/azure_jumpstart_arcbox/artifacts/RunAfterClientVMADJoin.ps1 @@ -36,9 +36,10 @@ Write-Host "====================================================" $cimsession = New-CimSession -Credential $adminCredential # Creating scheduled task for WinGet.ps1 -$Trigger = New-ScheduledTaskTrigger -AtLogOn +$Trigger = New-ScheduledTaskTrigger -AtLogOn -User $adminuser $Action = New-ScheduledTaskAction -Execute "pwsh.exe" -Argument $Env:ArcBoxDir\WinGet.ps1 -Register-ScheduledTask -TaskName "WinGetLogonScript" -Trigger $Trigger -CimSession $cimsession -Action $Action -RunLevel "Highest" -Force +$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -RunOnlyIfNetworkAvailable -NetworkName "Any" +Register-ScheduledTask -TaskName "WinGetLogonScript" -Trigger $Trigger -CimSession $cimsession -Action $Action -RunLevel "Highest" -Force -Settings $settings # Creating scheduled task for DataOpsLogonScript.ps1 $Action = New-ScheduledTaskAction -Execute "pwsh.exe" -Argument "$Env:ArcBoxDir\DataOpsLogonScript.ps1" @@ -64,4 +65,6 @@ net user $account /active:no # Delete schedule task schtasks.exe /delete /f /tn RunAfterClientVMADJoin +Restart-Computer -Force + Stop-Transcript \ No newline at end of file