Powershell Scripts called from within SharePoint

We have a request to offer access to Powershell scripts from an ASPX page. Theidea is if this works we can move it into SharePoint. Has anyone worked withthis?

Our initial problem seems to be the execution of the script. Working locallyfrom Visual Studio 2008 executes fine. But, once it is moved under the webserver it doesn't. The Event Viewer shows an error of "... An unhandledexception occurred and the process was terminated....".

If we can't get a simple 'Hello World' Powershell script to execute just underIIS, I don't hold much hope of getting it to work under SharePoint.

Just to repeat, this is a very simple ps script being called. It works from theps CLI. Just seems to hang when the asp page calls it. I just want to see thatit works, the concept. Then the idea is that our Exchange admin can write hisown PS cmdlets and we can drop them into an UI in Sharepoint.... a dashboard oftools of sorts.

This the one example on the subject that I could find:http://devinfra-us.blogspot.com/2008/05/powershell-and-aspnet.html

This is actually pretty easy, but has a strange hidden gotcha as far as impersonation goes. Most things in Sharepoint require impersonation, and, to use impersonation within PowerShell and ASPX, you need to set some properties on the the runspaces in a specific way (ThreadOptions = UseCurrentThread, ApartmentState = STA).

Go4Sharepoint, is a Microsoft Featured Community.
Microsoft, Windows, Sharepoint, Sharepoint logo, Windows logo, etc are trademarks of the Microsoft Corporation.
All product names, logos, copyrights, and trademarks mentioned are acknowledged as the registered intellectual property of their respective owners. This site is not in any way affiliated with, nor has it been authorized, sponsored, or otherwise approved by, Microsoft Corporation.