With powershell:
$TaskPath = "\"
$TaskName = "test"
$Action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "D:\123.ps1"
$Trigger = New-ScheduledTaskTrigger -AtLogOn
$ScheduledTask = New-ScheduledTask -Action $action -Trigger $trigger
Register-ScheduledTask -TaskName "$TaskPath$TaskName" -InputObject $ScheduledTask
$triggersession = " <Triggers>
<SessionStateChangeTrigger>
<Enabled>true</Enabled>
<StateChange>RemoteConnect</StateChange>
</SessionStateChangeTrigger>
<SessionStateChangeTrigger>
<Enabled>true</Enabled>
<StateChange>ConsoleConnect</StateChange>
</SessionStateChangeTrigger>"
$taskoutput = Export-ScheduledTask -TaskName $TaskName -TaskPath $TaskPath
$taskoutput = $taskoutput -replace " <Triggers>", $triggersession
Register-ScheduledTask -Xml $taskoutput -TaskName "$TaskPath$TaskName" -force
Friday, September 22, 2023
Add "on connection to user session" for task scheduler
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment