In order to be able to run a PowerShell script using the Task Scheduler, the Execution Policy typically needs to be set to RemoteSigned. To view the current Execution Policy, in PowerShell type Get-ExecutionPolicy. If the Execution Policy is not set to RemoteSigned, the Execution Policy can be set to RemoteSigned using the Set-ExecutionPolicy cmdlet.
Lets create a PowerShell script that outputs the current date and time to a file.
$date = Get-DateAdd-Content C:\Users\<username>\PowerShell_Scripts\current_date_time.txt " `n $date"
We next want to ensure we can run this script using PowerShell (not PowerShell ISE):
Follow these directions to automatically run this script using FBTaskScheduler.
Verify the task was successfully run:
In the left panel of Task Scheduler, select Task Scheduler Library, and the newly created PowerShell Current Date Time Task will be listed in the list of tasks. Before the task is run for the first time, Last Run Time will be never. After the task schedule has passed, right-click on Task Scheduler Library and select Refresh. The Last Run Time should display the time the task was run. Nnavigate to C:\\Users\\<username>\\PowerShell_Scripts\\ and open the current_date_time.txt file. Ensure the text file contains the date/time the task was scheduled to run.