Wednesday, November 15, 2023

Create schedule task using PowerShell

 

$Action = New-ScheduledTaskAction "powershell.exe "D:\ADScripts\Get-ADusers-RITM-Monthly-Report.ps1""

$Trigger = New-ScheduledTaskTrigger -Weekly -WeeksInterval 2 -DaysOfWeek Sunday -At 3am

$Principal = New-ScheduledTaskPrincipal -UserID AD-HMR$ -LogonType Password

$taskname = "AD Enabled Users List Monthly Report"

$Taskpath = "AD-Tasks"

$TaskDescription = "AD Enabled users List, This task will generate the Enabled users list and send it to Bix and bbntech as Attachment file."

Register-ScheduledTask  –Action $Action –Trigger $Trigger –Principal $Principal -TaskName $taskname -Description $TaskDescription -taskPath $Taskpath 

#$Time = New-ScheduledTaskTrigger -Monthly -WeeksInterval 4 -DaysOfWeek Monday -At 3am

#Set-ScheduledTask -TaskName "Arcosa Enabled Users List Monthly Report" –Principal $Principal -taskPath $Taskpath



No comments:

Post a Comment