Example of how to create a Windows Task Scheduler Task in PowerShell.

#
# Create a Windows Task Scheduler Task in PowerShell
#

# Define the user account to execute the script:
$taskUser = "Corp\ScriptAdmin"
$taskPassword = 'P@$$w0rd'

# Define the action to be executed:
$taskAction = New-ScheduledTaskAction -Execute "%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe" -Argument "C:\scripts\superUser.ps1"

# Define the execution schedule:
$taskTrigger = New-ScheduledTaskTrigger -Weekly -WeeksInterval 1 -At 5am -DaysOfWeek Sunday

# Name the task and register
$taskName = "Super User Report"
Register-ScheduledTask -TaskName $taskName -Action $taskAction -Trigger $taskTrigger -User $taskUser -Password $taskPassword