0

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.

BlackHatSamurai
  • 23,275
  • 22
  • 95
  • 156
Kenpachii
  • 145
  • 1
  • 13
  • Can't you just call your functions in script1. If you try a get-childItem function: what do you get ? – JPBlanc Aug 01 '13 at 19:40
  • @JPBlanc I get list of files in my bin folder: EXE, .config and DLLs – Kenpachii Aug 01 '13 at 21:14
  • Update: I have not been able to find a way to do this. So I have been concatenating strings. This is making debugging and error handling painful as I get a line# from logs but then have to put together all scripts called in one file to get to that line. – Kenpachii Aug 16 '13 at 14:09

0 Answers0