We powershell enthusiasts spend a lot of time scheduling jobs to run scripts of various sorts. That's a lot of repetitive work. You know what? If you are doing a job manually a lot, might be a good idea to script it.
Here's a quick function that wraps up the new-scheduled task commands and makes it quick and easy to schedule a powershell script.
function new-scheduledscript{
param(
[Parameter(Mandatory=$true)]
$scriptpath,
[Parameter(Mandatory=$true)]
$user,
[Parameter(Mandatory=$true)]
$password,
[Parameter(Mandatory=$true)]
$time,
[Parameter(Mandatory=$true)]
$taskname ) $A = New-ScheduledTaskAction –Execute C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe -Argument "-file `"$scriptpath`"" $T = New-ScheduledTaskTrigger -Daily -At $time $S = New-ScheduledTaskSettingsSet $D = New-ScheduledTask -Action $A -Trigger $T -Settings $S Register-ScheduledTask $taskname -InputObject $D -User $user -Password $password } |
Pulled the syntax for this from the documentation over here; https://technet.microsoft.com/en-us/library/jj649810(v=wps.630).aspx
No comments:
Post a Comment