ASP.NET Zone

Die ASP.NET Community. Alle Antworten rund um Microsoft® Webtechnologien
Willkommen bei ASP.NET Zone. Anmelden | Registrieren | Hilfe | Impressum | ASP.NET Zone Suchplugin

in
Home Blogs Foren FAQ Communities Fotos Downloads
Werbeanzeige

PowerShell Script Parameter Übergabe in einem Webdienst

Letzter Beitrag 05-30-2012, 13:45 von omega90. 0 Antworten.
Beiträge sortieren: Zurück Weiter
  •  05-30-2012, 13:45 224352

    PowerShell Script Parameter Übergabe in einem Webdienst

    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.

Als RSS Feed in XML ansehen
Powered by Community Server (Commercial Edition)