Scheduled Task Powershell Script - Runs OK as user account, but not as SYSTEM
Solution 1:
This isn't the answer why your specific script doesn't work under the SYSTEM account but explains how you might troubleshoot your (or any other) PowerShell Script under the SYSTEM account.
Give a man a fish, and you feed him for a day. Teach a man to fish, and you feed him for a lifetime.
The whole thing around this, is that you can actually open a interactive PowerShell command prompt under the SYSTEM account were you probably not aware of.
Run PowerShell as SYSTEM
There are a few ways to start a interactive PowerShell command prompt but probably the easiest one is using PsExec.
Using PsExec
- Download PsTools
- Extract
PSTools.zip
and just copyPsExec
into your executable path - Run
PowerShell
as Administrator (accept theUser AccountControl
prompt) - In the PowerShell administrator window, give the command:
.\PsExec -i -s -d PowerShell
- A new
PowerShell
command window will open:
(TypeWhoAmI
to confirm the current account)
From here you can troubleshoot the specific script:
- Are there any errors when running the specific script?
- Does it hang or crash at a specific command?
- Are there any differences with running it under a user account?
If it appears that the script runs actually fine in the SYSTEM window, then I would check for any errors in the Task Scheduler
:
- Select
Task Scheduler Local
-Task Scheduler Library
in the left pane - Select your task in the middle top pane
- (Make sure you have
Display All Task History
in the right paneEnabled
) - In the middle bottom pane check the events in the
history
tab