2010-06-12 9 views
11
RunspaceConfiguration psConfig = RunspaceConfiguration.Create(); 
Runspace psRunspace = RunspaceFactory.CreateRunspace(psConfig); 
psRunspace.Open(); 
using (Pipeline psPipeline = psRunspace.CreatePipeline()) 
      { 

      // Define the command to be executed in this pipeline 
      Command command = new Command("Add-spsolution"); 

      // Add a parameter to this command 
      command.Parameters.Add("literalpath", @"c:\project3.wsp"); 

      // Add this command to the pipeline 
      psPipeline.Commands.Add(command); 


       // Invoke the cmdlet 
      try 
      { 
       Collection<PSObject> results = psPipeline.Invoke(); 
       Label1.Text = "hi"+results.ToString(); 
       // Process the results 
      } 
      catch (Exception exception) 
      { 
       Label1.Text = exception.ToString();// Process the exception here 
      } 

     } 

Es wirft die Ausnahme:Run Powershell-Befehle in C#

System.Management.Automation.CommandNotFoundException: The term 'add-spsolution' is not recognized as the name of a cmdlet, function, script file, or operable program. 

Irgendwelche Vorschläge, warum?

+0

Haben Sie eine Lösung gefunden? –

Antwort

10

erste Befehl hinzufügen:

Add-PSSnapin Microsoft.SharePoint.Powershell -EA 0

-1

Auch stellen Sie sicher, Sie sind Ausführen des Befehls "Add-SPSolution" von Web Applications, der auf IIS ausgeführt wird und NICHT mit dem Standard-Visual Studio-Betriebssystem rver (wenn Sie F5 drücken).

2

Ich habe dieses Problem vor kurzem. In meinem Fall war ich weder in der Lage, die hinzugefügte Lösung zu sehen, noch konnte ich eine Lösung hinzufügen. Zuerst lösche ich die Lösung mit PowerShell Befehl:

Dann konnte ich meine neue Code-Lösung hinzufügen.