I have a C# application that runs PowerShell scripts after reading them off database as strings. Assume script1
, script2
and utilityfunctions
are scripts read from database.
var rs = RunspaceFactory.CreateRunspace();
rs.Open();
var ps = PowerShell.Create();
ps.Runspace = rs;
ps.AddScript(utilityFunctions);
ps.AddScript(script1);
Is there anyway possible that I can call functions in utilityFuntions
from script1
? I have tried using $MyInvocation
and go through its properties but did not find anything useful. When going through ps.Commands
properties, I can of course see two items but when going through commands within the script, I cannot get to anything inside utilityFunctions
. I guess I can read all scripts and concatenate them as string and only pass one script but I am just wondering if there is a way to do it without string concatenation.