I have a powershell script file.
i need to run this script file in my c# code to execute it.
please help.
What I have tried:
i tried this code.
in the psobjects i am not getting results. please help
RunspaceConfiguration runspaceConfiguration = RunspaceConfiguration.Create();
Runspace runspace = RunspaceFactory.CreateRunspace(runspaceConfiguration);
runspace.Open();
RunspaceInvoke scriptInvoker = new RunspaceInvoke(runspace);
Pipeline pipeline = runspace.CreatePipeline();
Command scriptCommand = new Command(scriptFile);
Collection<commandparameter> commandParameters = new Collection<commandparameter>();
int i = 0;
foreach (string scriptParameter in scriptParameters.Split(','))
{
CommandParameter commandParm = new CommandParameter(scriptName.Split(',')[i], scriptParameter);
commandParameters.Add
(commandParm);
scriptCommand.Parameters.Add(commandParm);
i++;
}
pipeline.Commands.Add(scriptCommand);
Collection<psobject> psObjects;
psObjects = pipeline.Invoke();