Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Reply To: Executing Powershell from C#

$
0
0

Hi Dave,
I have basically moved the following into and out of the loop that iterates of the data set:

Collection&ltPSObject&gt results;
using (PowerShell powerShell = PowerShell.Create())
{
    // Source functions.
    powerShell.AddScript(PsScript);
    powerShell.Invoke();
 
    // Call function contained in sourced script above.
    powerShell.AddCommand("My-Function");
    powerShell.AddParameter("ParamA", varA);
    powerShell.AddParameter("ParamB", varB);
    powerShell.AddParameter("ParamC", varC);
    powerShell.AddParameter("ParamD", varD);
 
    results = powerShell.Invoke();
}

I'd love to remove the powershell but this is the premise of the program, it provides an easy to modify scriptable environment.
Its fundamental that for each usage of the compiled code, you have access to user defined functions.

Aside from the above, I have tried all sorts of appraoches using RunSpaces etc to no avail.

Thanks!


Viewing all articles
Browse latest Browse all 13067

Trending Articles