Ich habe ein Webservice geschrieben der ein Script ausführt...soweit so gut. das ganze funktioniert auch eigentlich recht gut jedoch hat dieses Script keine Parameter. Das neue Script schon ....den Parameter $Projektnummer.
Mein C# Code sieht wie folgt aus ....
using System.Diagnostics;
using System.Collections.ObjectModel;
using System.IO;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
...
private void btnExecute_Click(object sender, EventArgs e)
{
...
try
{
RunScript(txtPath.Text);
lblInfo.Text = "Script wurde ausgeführt";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
...
}
...
Collection<PSObject> RunScript(string filename)
{
string psScript = string.Empty;
if (File.Exists(filename))
{
psScript = File.ReadAllText(filename);
}
else
{
Console.WriteLine("wrong path");
}
Runspace runspace = RunspaceFactory.CreateRunspace();
runspace.Open();
RunspaceInvoke runSpaceInvoke = new RunspaceInvoke(runspace);
runSpaceInvoke.Invoke("Set-ExecutionPolicy Unrestricted");
Pipeline pipeline = runspace.CreatePipeline();
pipeline.Commands.AddScript(psScript);
pipeline.Commands.Add("Out-String");
Collection<PSObject> returnObjects = pipeline.Invoke();
runspace.Close();
return returnObjects;
}
Das Problem ist jetzt nur wie übergebe ich Parameter :(
Gruß w.t.