I am writing PS script that will be integrated with the C# based Windows Form Application. This is what I have tried/done already:
-
I am able to run PS scripts through the runspace and pipeline, however i encounter the error while I am trying to run the script that uses functions, saying: ” Cannot invoke this function because the current host does not implement it.”
-
I have researched the problem and I have found very few people who had encoutered similar problem, however one of the solutions underlined that I need to use (add) the following $ConfirmPreference = “None”, ,-Confirm:$false, -Force
-
However when I tried that the following error message appeared: ” Missing expression after unary operator ‘-‘. “ You can see that I have tried to concatenate the strings by assigning them to the variables, but that did not help. I do not have any idea how to solve it, has anyone got any ideas? Any help will be much appreciated.
// create Powershell runspace Runspace runspace = RunspaceFactory.CreateRunspace(); // open it runspace.Open(); // create a pipeline and feed it the script text Pipeline pipeline = runspace.CreatePipeline(); //allow the functions to be exec string sa = "$ConfirmPreference = \"None\" "; string se = " -Confirm:$false -Force"; string s = sa +scriptText + se; pipeline.Commands.AddScript(s);
-Confirm:$false -Forceare meant to be function parameters, they don’t exist on their own.But even if you modify every function call with these parameters, it probably won’t solve all of your issues. See here for more options.