Sitecore powershell is a must have module on all Sitecore instances. The Sitecore PowerShell Extensions (SPE) module is a Sitecore development accelerator which can drastically increase your productivity and curtail the amount of time it takes to deliver a Sitecore solution.
I wanted to get start with the Sitecore powershell and decided to implement a script which will ask the user some input which I will process in the backend, that is, in the code. So, let’s get start.
First of all, let’s define the scenario. The user should be able to
- Insert a text in a textbox.
- Select a template from a droptree.
- Pass the input information to a method in the code.
- Return and alert the result.
The Powershell Script
The powershell script will look as follows:
This feature is called splatting and it allows for a better understanding of the script:
What is does now is that it will create a Sheer UI modal with a textbox and a droptree as shown below:
The statements shown below are responsible to call the method from the code. The New-Object will create a new instance of the class Demo and the GetResponse() is a method of the Demo class.
Note that you can also call a static class as follows:
Once the method is called, you can perform the different logic on the value then returns it back to the powershell. As example:
The $response will contain the result from the method GetResponse() which you can then alert or perform more processing via the powershell script.
Special thanks to Michael West for introducing me to the Powershell world 🙂