I need to excecute a PowerShell script from a ListEventReceiver
under special User credentials. I found the Runspace
which is working very fine to excecute scripts but how to make a secure (no passwords in the code) "run as"?
Pipeline
string cmdArg = "C:\\Users\\Administrator\\Documents\\userExist.ps1 " + mailstring;
Runspace runspace = RunspaceFactory.CreateRunspace();
runspace.Open();
Pipeline pipeline = runspace.CreatePipeline();
pipeline.Commands.AddScript(cmdArg);
pipeline.Commands[0].MergeMyResults(PipelineResultTypes.Error, PipelineResultTypes.Output);
Collection<PSObject> results = pipeline.Invoke();
var error = pipeline.Error.ReadToEnd();
runspace.Close();
I read about secure store service but I think it is only for whole services, pages or lists and can't be used for single functions?
Does any one have an idea how to solve this problem?