feat: make username in Initialize.ps1 dynamic (#15751)

This PR switches the `UserId` from a constant to a generated values
based on the script environment. This enables users to rename their
machine and default user name without having to edit this element as
well.
This commit is contained in:
Charlie Voiselle
2024-12-06 08:16:32 -05:00
committed by GitHub
parent bae12e1f0b
commit 9fe71d9daa
@@ -64,7 +64,7 @@ $task = @{
Action = (New-ScheduledTaskAction -Execute 'powershell.exe' -Argument '-sta -ExecutionPolicy Unrestricted -Command "C:\AzureData\CoderAgent.ps1 *>> C:\AzureData\CoderAgent.log"')
Trigger = (New-ScheduledTaskTrigger -AtStartup), (New-ScheduledTaskTrigger -Once -At (Get-Date).AddSeconds(15))
Settings = (New-ScheduledTaskSettingsSet -DontStopOnIdleEnd -ExecutionTimeLimit ([TimeSpan]::FromDays(3650)) -Compatibility Win8)
Principal = (New-ScheduledTaskPrincipal -UserId 'vm\coder' -RunLevel Highest -LogonType S4U)
Principal = (New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\$env:USERNAME" -RunLevel Highest -LogonType S4U)
}
Register-ScheduledTask @task -Force