I am creating an asp.net mvc application that will work as a wrapper for a number of powershell scripts that we have written to manage everyday tasks (with the ultimate goal of making scripting easier for non-technical people).
I managed to get scripts to execute beautifully:
var ctx = System.Web.HttpContext.Current; var file = ctx.Server.MapPath("~/Content/Powershell/psStoreLive.ps1");
The problem is that the scripts are executed as IIS_USR (or similar).
I need to find a way to get the IIS server to execute scripts as the current logged-in user (using Windows authentication ( <authentication mode="Windows" /> ).
I saw http://stackoverflow.com/questions/10837377/loginview-and-passing-credentials-to-powershell , and although it seems like this might work, this idea does not suit me.
It seems to me that I should do this with some C # code, as in the code block above, but I couldn’t change anything with the help of my searches that do this.
How to create a powershell environment in C # that will run as a registered user (I would even agree to re-request credentials if necessary)
thanks
Change 1
I looked at the PSCredential object and it seems correct, but I still cannot figure out how I can connect it to the session as a whole (a lot of information about using it as a parameter for a cmdlet requiring credentials)
source share