23 lines
863 B
PowerShell
23 lines
863 B
PowerShell
#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"
|