Interested in Sitecore?

Apply for our Mentorship Program by emailing your resume to chris.williams@techguilds.com. Check out our ASP.NET QuickStart and C# QuckStart Libraries. Below is my latest articles.

Sunday, April 16, 2017

Running Powershell Scripts from your Application

I have been working on a Feed Processing Library for many years now.  It featured its own simple Automation Script however in recent years I have seen the power of PowerShell scripts and am integrating it into my Feed Processor.  While doing this, I made notes below so it would help you through the same process of using it in your applications.

The first step is adding the reference to System.Management.Automation.dll to your solution. Although there are many ways to do this Rasik Bihari answered the best way to do it: Thanks Rasik Bihari for the answer.
System.Management.Automation dll is now published as "System.Management.Automation" nuget package here. Just add a reference to this nuget package from visual studio nuget package manager in your project and get going.
It shows like this in your packages.config file once you have installed the above mentioned nuget package in your project: 
<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="System.Management.Automation.dll" version="10.0.10586.0" targetFramework="net452" />
</packages>
Once added, you can follow the recipe on how to run PowerShell Script from C#.