how to create schedule task using powershell

how to create schedule task using powershell?

windows 7 or less

if you dont have TaskScheduler module installed on your system or if you are running windows 7 or less version then you might have to use old commands

replace task schedule, name , script file with correct data before use**

407-2

$T = New-JobTrigger -Weekly -DaysOfWeek 1,3,5 -At 12:01AM
Register-ScheduledJob -Name Test-HelpFiles1 -FilePath "C:\runas.ps1" -Trigger $T 

windows 8 or higher

If you are running windows 8 or higher version then use below code:

410-2

ipmo ScheduledTasks
$action = New-ScheduledTaskAction -Execute 'Powershell.exe' -Argument '-NoProfile -WindowStyle Hidden -command "& {get-eventlog -logname Application -After ((get-date).AddDays(-1)) | Export-Csv -Path c:\temp\applog.csv -Force -NoTypeInformation}"'
$trigger =  New-ScheduledTaskTrigger -Daily -At 9am
Register-ScheduledTask -Action $action -Trigger $trigger -TaskName "AppLog" -Description "Daily dump of Applog" 
(Visited 718 times, 1 visits today)
One Comment

Add a Comment

Facebook