![]() $tr = New-ScheduledTaskTrigger -AtLogOn -User $env:USERNAME $ac = New-ScheduledTaskAction -Execute "cmd.exe" -Argument "/c timeout.exe /t 5" (If you're in a domain, you might also need to include that name.) unregister-scheduledtask -TaskName "Test02" -confirm:$false To create the task when the author of the task logs in, use this. I noticed that the -AtLogOn would cause it to be executed at the logon of any user, but the runas was set to the author of the task, so it would fail. The trick appears to be that you need to copy the repetition from another trigger. But do you really need to create it first then update it to get it work? Can't you do it directly like in example 2? ![]() $ta = Register-ScheduledTask -TaskName "Test03" -Trigger $tr -Action $ac Goal: To create a Scheduled Task trigger on user logon with a repetition and a duration.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |