Skip to content

Instantly share code, notes, and snippets.

@K-Mistele
Created June 28, 2021 13:40
Show Gist options
  • Save K-Mistele/9e0469b9286e1e65e88b248856ed49ee to your computer and use it in GitHub Desktop.
Save K-Mistele/9e0469b9286e1e65e88b248856ed49ee to your computer and use it in GitHub Desktop.
Schedule a task as another user with PowerShell
$action=New-ScheduledTaskAction -Execute 'powershell.exe' -Argument '-windowstyle hidden -ep bypass C:\path\to\script.ps1';
$trigger=New-ScheduledTaskTrigger -Once -At 'MM/DD/YYYY HH:MM:SS PM';
Register-ScheduledTask -Action $action -Trigger $trigger -TaskName 'Launch' -User 'DOMAIN\username'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment