Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- **#This is sample PowerShell function**
- function Add-num {
- param($int1,$int2)
- Write-Host ($int1 + $int2)
- }
- **#This is my c# code**
- class Program
- {
- static void Main(string[] args)
- {
- String file = @"E:powershellUntitled3.ps1";
- Runspace runspace = RunspaceFactory.CreateRunspace();
- runspace.Open();
- using (PowerShell PowerShellInstance = PowerShell.Create())
- {
- PowerShellInstance.AddScript(file);
- PowerShellInstance.AddCommand("Add-num").AddParameters(new Dictionary<string, string>
- {
- {"int1","6" },
- {"int2","7" }
- });
- // Collection<PSObject> PSOutput = PowerShellInstance.Invoke();
- foreach (PSObject outputItem in PowerShellInstance.Invoke())
- {
- Console.WriteLine(outputItem.BaseObject);
- }
- runspace.Close();
- }
- }
- }
Add Comment
Please, Sign In to add comment