Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Powershell Scripts called from within SharePoint

  Asked By: Traci    Date: Aug 21    Category: Sharepoint    Views: 2201

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

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

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



7 Answers Found

Answer #1    Answered By: Miranda Scott     Answered On: Aug 21

Assuming that you have PowerShell loaded on SharePoint, are you loading the
SharePoint assembly?

Answer #2    Answered By: Deirdre Macias     Answered On: Aug 21

I can run the script  from the PS command line on the server. Executes fine.
After execution  on the web server, I see the following errors when I run Process

10:07:40.6264249 AM w3wp.exe 3048 QueryOpen

10:07:40.6264807 AM w3wp.exe 3048 CreateFile
PATH NOT FOUND Desired Access: Read Attributes, Disposition:
Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write,
Delete, AllocationSize: n/a

As for assemblies loaded, these are those:

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.IO;

Answer #3    Answered By: Kala Solomon     Answered On: Aug 21

Really dumb question is this server Windows 2008?

Answer #4    Answered By: Madison Clark     Answered On: Aug 21

It is 2008. I've also disabled the UAC via MSCONFIG/rebooted. No change.

Here is screen shot of profiles:

Answer #5    Answered By: Dhanraj Saxsena     Answered On: Aug 21

Some more information.... looking at the System logs, I see the following:

A process serving application pool 'helpdesk-test.ad.ufl.edu' suffered a fatal
communication error with the Windows Process Activation Service. The process id
was '1172'. The data field contains the error number.

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

This the one example on the subject that I could find:

Answer #6    Answered By: Kacie Calhoun     Answered On: Aug 21

Did you look at this technet site:

Answer #7    Answered By: James Brundage     Answered On: Apr 12

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).

Alternatively, you can just use the PowerShell web platform we build, which includes this trickery - PowerShell Pipeworks. powershellpipeworks.com/ConvertFrom-InlinePowerShell should actually convert the scripts into ASP.NET for you.

Hope this helps,


Didn't find what you were looking for? Find more on Powershell Scripts called from within SharePoint Or get search suggestion and latest updates.