I have some custom powershell cmdlets in several scripts, one of which i've loaded an executed as such in C#
string Script2 = File.ReadAllText(@"C:\blabla\blabla\ScriptPowershell\TestCheck.ps1");
shell.Commands.Clear();
shell.AddScript(Script2, false);
shell.Invoke();
shell.Commands.Clear();
shell.AddCommand("TestCheck").AddParameter("ServerName", $"{serverId}").AddParameter("ServerPort", $"{serverPort}");
Collection<PSObject> psObjects = shell.Invoke();
The main issue with this is that if I publish and install this app on another computer that surely might not have this script at the same exact directory, the cmdlet will not work.
QUESTION : Is there a way to publish the app with the scripts joined to it, so that it doesn't need to search in the users computer for the scripts ? Or at least be present in the same directory as the .exe
Any suggestion to solve this problem is welcome.
Thank you !
Edit 1 : In response to @despacito this is the error message after appyling his solution