The Environment: Windows 10 workstation. This isn't being uploaded from a server, it's being uploaded from a workstation because I have to manually update the file daily. This is also a temporary solution until we get the new system up and running.
The Problem: I have a Powershell script that will run fine when launched manually, however, when I try to launch it through Task Scheduler, TS says the Last Run Result "The operation completed successfully (0x0)" but the file wasn't uploaded. Now, when I run the script manually, a Powershell window will open while the script runs but nothing shows on the screen, then when the script is finished running, the window closes. This window does not appear when the Task Scheduler runs the script - leading me to believe that TS is not really running the script.
What I've Tried:
- Changing the name of the user account running the task (myself, SYSTEM, LOCAL SERVICE*)
- Running Powershell from both C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe and C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe
- Adding -ExecutionPolicy Bypass to the arguments box
- Adding the full path to the Start In box
- Creating it as a Basic Task and just Task
- Sitting on the warp engines and nursing them in spite of it being an unavailing and undignified position
I'm including the XML code for my task in case someone sees something in there that I may be missing.
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.4" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2021-04-16T13:34:17.5511135</Date>
<Author>(redacted)</Author>
<URI>\Nightly Update Staff</URI>
</RegistrationInfo>
<Triggers>
<CalendarTrigger>
<StartBoundary>2021-04-16T17:05:00</StartBoundary>
<ExecutionTimeLimit>PT30M</ExecutionTimeLimit>
<Enabled>true</Enabled>
<ScheduleByWeek>
<DaysOfWeek>
<Monday />
<Tuesday />
<Wednesday />
<Thursday />
<Friday />
</DaysOfWeek>
<WeeksInterval>1</WeeksInterval>
</ScheduleByWeek>
</CalendarTrigger>
</Triggers>
<Principals>
<Principal id="Author">
<UserId>S-1-5-19</UserId>
<RunLevel>HighestAvailable</RunLevel>
</Principal>
</Principals>
<Settings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
<AllowHardTerminate>true</AllowHardTerminate>
<StartWhenAvailable>false</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<IdleSettings>
<StopOnIdleEnd>true</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>false</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
<UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine>
<WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>PT1H</ExecutionTimeLimit>
<Priority>7</Priority>
</Settings>
<Actions Context="Author">
<Exec>
<Command>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe</Command>
<Arguments>-ExecutionPolicy Bypass C:\StaffUpload.ps1</Arguments>
<WorkingDirectory>C:\Users\%username%\Desktop</WorkingDirectory>
</Exec>
</Actions>
</Task>
What I may be doing wrong?
*NOTE - LOCAL SYSTEM gave me a Directory not found error
Start-Transcriptat the beginning of your script to log its actions.C:\Users\%username%\folder, so make sure yourWorkingDirectorytakes that into account. Make sure that the file paths for the stuff you're uploading all work properly as well in the context of whatever user is supposed to run the script. Your task looks fine otherwise and it is running - can you add the powershell script to your question instead of the task xml?