PowerShell Script with ASP.NET and Console Application

I have two projects that need to incorporate Windows PowerShell, Exchange Management Shell and ActiveRoles Management Shell for AD (by Quest) in a ASP.NET and a Console Application recently, so I started to look for information about PowerShell scripting with .NET and below are two important articles in my opinion:

  1. HOWTO: Using PowerShell in ASP.NET (.NET Framework 2.0)

The first article explains the most challenging issues in hosting PowerShell scripting with ASP.NET - Security context and permission and describe three common optioins. The second article describes the logic and tips in writing PowerShell in .NET managed code application.

I wrote a small class to execute the PowerShell script, by passing in various script text on the fly. Below is a small code snippet:

  private const string PS_SNAP_IN_MICROSOFT = "Microsoft.Exchange.Management.PowerShell.Admin";
  private const string PS_SNAP_IN_QUEST = "Quest.ActiveRoles.AdManagement";

            RunspaceConfiguration rsConfig = RunspaceConfiguration.Create();
            PSSnapInException snapInException = null;
            rsConfig.AddPSSnapIn(PS_SNAP_IN_MICROSOFT, out snapInException); // Add Exchange Mgmt SnapIn
            rsConfig.AddPSSnapIn(PS_SNAP_IN_QUEST, out snapInException);  // Add Quest Mgmt SnapIn
           
            Runspace myRunspace = RunspaceFactory.CreateRunspace(rsConfig);
            myRunspace.Open();

            Pipeline pipeLine = myRunspace.CreatePipeline();
            pipeLine.Commands.AddScript(scriptText);  // Pass in the script text on the fly
            pipeLine.Commands.Add("Out-String"); 

            Collection<PSObject> cmdResults = pipeLine.Invoke();

            myRunspace.Close();

After preparing these PowerShell scripting in .NET app, I'd suggest to stick with PowerShell because it's handy and flexible. I'd prefer it over DirectoryServices or CDOEXM commands. :) Read the useful articles mentioned above in sequence then you are ready to start coding!

Regards,
Colt

Published Monday, August 17, 2009 11:04 PM by Colt
Filed under: ,

Comments

# PowerShell Script with ASP.NET and Console Application &#8211; Colt &#8230; | Webmaster Tools

Pingback from  PowerShell Script with ASP.NET and Console Application &#8211; Colt &#8230; | Webmaster Tools

# PowerShell Script with ASP.NET and Console Application - Colt &#8230;

Pingback from  PowerShell Script with ASP.NET and Console Application - Colt &#8230;

# PowerShell Script with ASP.NET and Console Application - Colt &#8230; Scripts Rss

Pingback from  PowerShell Script with ASP.NET and Console Application - Colt &#8230; Scripts Rss

# PowerShell Script with ASP.NET and Console Application &#8211; Colt &#8230; | Neorack Tutorials

Pingback from  PowerShell Script with ASP.NET and Console Application &#8211; Colt &#8230; | Neorack Tutorials

# re: PowerShell Script with ASP.NET and Console Application

awesome to the point and exactly what i needed thanks!

Friday, January 08, 2010 5:57 PM by carter cole

# Powershell and ASP.NET

Powershell and ASP.NET

Friday, April 16, 2010 1:21 PM by my great discovery

# re: PowerShell Script with ASP.NET and Console Application

Powershell great article thanks and Asp.net

Wednesday, April 13, 2011 1:46 PM by jigolo

# re: PowerShell Script with ASP.NET and Console Application

every aspect of your site is really very well designed and carefully crafted articles have been written in regards wish you continued success..

Saturday, May 07, 2011 7:21 PM by hava perdesi

# re: PowerShell Script with ASP.NET and Console Application

thnk you for sahring

Sunday, May 08, 2011 3:50 PM by escort bayan

# re: PowerShell Script with ASP.NET and Console Application

Everything is explained in detail relevant to the subject site is within the existing social networking sites I came across a very impressive skins and best regards I wish you continued success with your site, I found the opportunity to examine in detail...

Thursday, May 12, 2011 12:02 PM by hava perdeleri

# re: PowerShell Script with ASP.NET and Console Application

Everything is explained in detail relevant to the subject site is within the existing social networking sites I came across a very impressive skins and best regards I wish you continued success with your site, I found the opportunity to examine in detail...

always good fun to listen to the radio, but also makes the radio is beautiful music played in

Tuesday, May 31, 2011 6:48 AM by hava perdesi

# re: PowerShell Script with ASP.NET and Console Application

Thanks very much always

Sunday, June 05, 2011 9:56 AM by hava perdeleri

# re: PowerShell Script with ASP.NET and Console Application

When you first log into Facebook you are taken to a home page where you can see recent status updates of your Friends. Keep an eye on the status updates and comment on them when appropriate.

Saturday, July 09, 2011 9:55 AM by ilahi dinle

# re: PowerShell Script with ASP.NET and Console Application

powershell script wonderful web page home page where you can see recent status updates of your Friends.

Monday, October 03, 2011 3:27 AM by web tasarim

# re: PowerShell Script with ASP.NET and Console Application

nore igrace <a href=www.vsezasport.si/.../kompresijska-oblacila>Kompresijska oblacila</a> za sprostitev.

Tuesday, November 22, 2011 11:06 AM by kovacz

# re: PowerShell Script with ASP.NET and Console Application

Thanks for sharing. Very impressive

Monday, December 05, 2011 5:41 AM by escort bayan

# re: PowerShell Script with ASP.NET and Console Application

public lectures and events featuring world renowned figures since January 2012. You can listen to them or download them here

Thursday, January 12, 2012 8:54 AM by izmir rent a car

Leave a Comment

(required) 
(required) 
(optional)
(required)