Running PowerShell Script in Task Scheduler

I've looked through the entire PowerShell script in Task Scheduler answers in other questions and couldn't find one that resolves this.

I tried to run the PowerShell task manager script with direct access:

       powershell.exe -file c:\path_to_your_script\script.ps1

      

As well as creating a package to run a PowerShell script.

The PowerShell script works great when it is launched by itself, as well as when manually launching a package.

It opens Excel, refreshes it, saves and closes.

I cannot successfully schedule this through the task handler.

Any advice?

thanks for the help

Edited:

@luke is the export of task scheduler settings

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
<Date>2015-05-11T12:40:51.6084684</Date>
<Author>----------</Author>
  </RegistrationInfo>
  <Triggers>
 <TimeTrigger>
  <Repetition>
    <Interval>PT1H</Interval>
    <StopAtDurationEnd>false</StopAtDurationEnd>
  </Repetition>
  <StartBoundary>2015-05-11T12:30:00</StartBoundary>
  <Enabled>true</Enabled>
</TimeTrigger>
  </Triggers>
  <Principals>
<Principal id="Author">
  <UserId>------\Administrator</UserId>
  <LogonType>Password</LogonType>
  <RunLevel>HighestAvailable</RunLevel>
</Principal>
  </Principals>
  <Settings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
<AllowHardTerminate>true</AllowHardTerminate>
<StartWhenAvailable>true</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<IdleSettings>
  <StopOnIdleEnd>true</StopOnIdleEnd>
  <RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>true</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<WakeToRun>true</WakeToRun>
<ExecutionTimeLimit>P3D</ExecutionTimeLimit>
<Priority>7</Priority>
  </Settings>
  <Actions Context="Author">
<Exec>
  <Command>C:\Windows\System32\cmd.exe</Command>
  <Arguments>/q /c "C:\Users\---------\Documents\PowerBI\PowerShell\RunExcelRefreshingScriptPowerShell2.bat"</Arguments>
</Exec>
  </Actions>
</Task>

      

+3


source to share


2 answers


You can provide export of task schedule settings without username or password.

I have a lot of powershells that are run through the Task Scheduler and not one problem because I have my scheduler that is called by a bit that starts powershell.



TaskSchedulerLastRunResult

and here you will find the result of the last run.

+1


source


I had the same problem when I created a scheduled task to run the generated PowerShell script. I found that if you add the path to the Powershell.exe file (ie:% SystemRoot% \ system32 \ WindowsPowerShell \ v1.0 \ powershell.exe) in the Program / script window and the path to your actual PowerShell script (ie: D : \ Scripts \ PowershellScript.ps1) (see example below) in the Arguments window it will work. You will also need to check the Server PowerShell Execution Policy to make sure it is set to "unlimited". You can also try adding it as an argument (-ExecutionPolicy Bypass). Hope this helps someone. Example: Running PowerShell Scripts



0


source







All Articles