Execute PowerShell Script with Sitecore Scheduler

If you have a requirement like execute PowerShell script in form of a scheduler then Sitecore Scheduler provides an option for the same.

For Example, you want to delete some Sitecore Items after a specific date or remove the ideal user at some specific time. For that, you have written a PowerShell script instead of C# code and you want to schedule the PowerShell Script with a Scheduler. Then Sitecore Scheduler provides you a good option to execute PowerShell Script.

If you want to know How to Install the PowerShell module with your Sitecore instance and the ideas about the PowerShell command and Scripts then, please refer series of blog posts written on: PowerShell with Sitecore.

Here I am giving you an example to create a Sitecore Item using PowerShell Script and Schedule that Script by Sitecore Scheduler. You can update your PowerShell script as per your requirement.

Step 1: Go to the PowerShell ISE, you can open it by Sitecore Launchpad or Sitecore -> Development Tools -> Sitecore ISE. It opens an Integrated Scripting Environment for you. Write your PowerShell scripts and check if it is working fine or not. To know about PowerShell ISE, see the blog Post:  PowerShell with Sitecore and Installation.

Execute_Pse_with_Sc_Scheduler_1

Step 2: Save the script. I have named, Create Course Items. You can locate it in the content tree under System -> Module -> PowerShell path. My Script path is: /sitecore/system/Modules/PowerShell/Script Library/Create Course Items

Execute_Pse_with_Sc_Scheduler_2

Step 3: Go to the Scheduler path by /sitecore/system/Tasks/Schedules. Right Click on Schedules and select the Schedule option from Insert Menu. You can select PowerShell Scripted Task Scheduler as well but here I am selecting the Schedule option to make it simpler. I have named it SpeScheduler.

Execute_Pse_with_Sc_Scheduler_3

Step 4: Select the PowerShell Script Command from the Dropdown icon in the Command input box. Enter your earlier saved PowerShell Script path into the Items input box. Enter a specific time interval in the Schedule input box. Now your scheduler is ready to schedule. For more details about How to specify the time in the Schedule input box, see the blog post: Create and Configure Scheduler in Sitecore

Execute_Pse_with_Sc_Scheduler_4

Step 5: Execute the scheduler and check your desired output. In my script, it will create a new item under defined parent path in script.

Execute_Pse_with_Sc_Scheduler_5

Happy Sitecoreing ðŸ˜Š

Comments

Popular posts from this blog

Sitecore Installation Error: Failed to Start Service 'Sitecore Marketing Automation Engine'

Import CSV Data in Sitecore Using PowerShell: Part-3

Sitecore : The database principal owns a schema in the database, and cannot be dropped message