Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- string script = System.IO.File.ReadAllText(@"C:UsersBobDesktopCallPS.ps1");
- using (Runspace runspace = RunspaceFactory.CreateRunspace())
- {
- runspace.Open();
- using (Pipeline pipeline = runspace.CreatePipeline(script))
- {
- Command c = new Command("BatAvg",false);
- c.Parameters.Add("Name", "John");
- c.Parameters.Add("Runs", "6996");
- c.Parameters.Add("Outs", "70");
- pipeline.Commands.Add(c);
- Collection<PSObject> results = pipeline.Invoke();
- foreach (PSObject obj in results)
- {
- // do somethingConsole.WriteLine(obj.ToString());
- }
- }
- }
- Function BatAvg
- {
- param ($Name, $Runs, $Outs)
- $Avg = [int]($Runs / $Outs*100)/100
- Write-Output "$Name's Average = $Avg, $Runs, $Outs "
- }
- using (Runspace runspace = RunspaceFactory.CreateRunspace())
- {
- runspace.Open();
- PowerShell ps = PowerShell.Create();
- ps.Runspace = runspace;
- ps.AddScript(script);
- ps.Invoke();
- ps.AddCommand("BatAvg").AddParameters(new Dictionary<string, string>() {
- {"Name" , "John"}, {"Runs", "6996"}, {"Outs","70"}
- });
- foreach (PSObject result in ps.Invoke())
- {
- Console.WriteLine(result);
- }
- }
- var ps = PowerShell.Create();
- ps.AddScript(script);
- ps.Invoke();
- ps.AddCommand("BatAvg").AddParameters(new Dictionary<string, string>
- {
- {"Name" , "John"}, {"Runs", "6996"}, {"Outs","70"}
- });
- foreach (var result in ps.Invoke())
- {
- Console.WriteLine(result);
- }
Add Comment
Please, Sign In to add comment