At last, we call the Invoke() Method to execute our command in a pipeline. This method returns a collection of PSObject.

4) Display result

Then, we browse this PSObject collection to display the result. Note that we call the “BaseObject” property of each PSObject, this property hold the original object that was decorated in the PSObject object.

That’s it ! now if you build this project, you should be able to display the result of your script in the result TextBox.

Now we’ll see how to publish this website, and how to specify a specific account for execution.

Website publication

Now that we have a working sample, we’ll publish this website in IIS and specify a custom identity for code execution.

Go to Build > Publish

Choose a target location (Inetpub/wwwroot is the default repository folder for IIS, but you can publish your website in any directory, as long as you set up access rights properly)

After that, open IIS management console, right click on the default web site and select “Add Application”

Note : you can also create a new website on your IIS server or delete the default website to create your own. Creating an application let you access your Website by it’s name like this : http://localhost/MyApplication

Gives a name to your application or website, then click “OK”

Now your application is ready, we’ll now choose a custom identity for our website. This identity will be used to execute your PowerShell scripts. There are many ways to set identity for a website, we’ll cover in this first post the most basic ones.

Anonymous authentication

This method is the easiest. We’ll define an anonymous authentication to our website, and choose a custom identity to run our commands. This is easy, but with severe drawbacks :

Anyone can access our website and will execute commands with the identity provided (we can mitigate this with specific access rights on the website folder, but this is clearly not the most secured method, you’re warned !)

Select your application, then click on the “Authentication” icon

Right click on “anonymous authentication” and select “Activate”, then Edit…

Choose “Specific "User”, click Set

Then fill your service account identity

That’s it : your code will be executed with this identity, regardless of the identity of the user.

Application Pool Identity

In more evolved scenarii, we can disable anonymous authentication and still use a custom identity for our website execution. This identity is set in an “Application Pool”.

Application Pools can be seen as an execution context for a website/web application (I make it short here), we won’t go in the details, but there’s many interesting features behind the application pool concept. One is to be able to set windows integrated authentication to authenticate user and use the application pool identity to run our code.

Note: we can set an Application pool and still use anonymous authentication, in the previous screen you have the option to use the application pool identity for your anonymous connection.

error opening the file....the imported project c:\program files(x86)\msbuild\microsoft\visualstudio\v10.0\webapplications\Microsoft.webapplication.targets" was not found. Confirm that the path in the declaration is correct and that the file exists on disk

Im using the code as is with no modifications. I can get many Exchange 2010 cmdlets to execute properly.. such as get-mailbox domain\user etc..

However when I execute get-mailboxsearch I get no results!?? on the web server im getting the following error..

The description for Event ID 6 from source MSExchange CmdletLogs cannot be found. Either the component that raises this event is not installed on your local computer or the installation is corrupted. You can install or repair the component on the local computer.

If the event originated on another computer, the display information had to be saved with the event.

This will work fine when I click execute the first time. If I click again or try a different Powercli script, I get the following error:nullReferenceException was unhandled by user codeObject reference not set to an instance of an object.

Not sure why it is passing null values for the same script that worked on previous execute.

Hope someone can help me troubleshoot this. I created my own project using methods outlined by you in this article, and consistently recieve a Unable to access Windows PowerShell PowerShellEngine registry information. My project is developed on Win7 64bit and deployed to Windows 2008 r2.