Scheduling PowerShell Script using Windows Scheduler

Suppose if you want to extract a report from a SharePoint library on a daily basis at a specified time,  the best option would be writing a PowerShell script and schedule it to run .In this Blog, I'm providing an example for the same.
  
Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
$fromfile = "Mydocs/Reports.xlsx"

$tofile   = "D:\test\
Reports.xlsx"

$web = Get-SPWeb http://mysites/site/
$file = $web.GetFile($fromfile)
$filebytes = $file.OpenBinary()

$filestream = New-Object System.IO.FileStream($tofile, "Create")
$binarywriter = New-Object System.IO.BinaryWriter($filestream)
$binarywriter.write($filebytes)
$binarywriter.Close()
Steps to Schedule the PowerShell Script
  1. Save the script as Myscript.ps1
  2. Start > All Programs > Accessories > System Tools
  3. In the Task Scheduler, select the Create Task option under the Actions heading on the right-hand side.
  4. Enter the name for the task, and give it a description

    • In the General tab, go to the Security options heading and specify the user account
    • Next, select the Triggers tab, and click New to add a new trigger for the scheduled task. This new task should use the On schedule option.
    • Start in (optional) box, add the location of the folder that contains your PowerShell script.
    • Next, go to the Actions tab and click New to set the action for this task to run. Set the Action to Start a program.
    • In the Program/script box enter "PowerShell.exe"
 Click Ok after all your changes.