1

I try to launch ps1 with parameter files from a c# program. But before this, I try to do it smaller, and run a "ls ." but it don't work, and I think that my code is OK.

pipeline.Commands.Add("ls ."); //in future here path of .ps1 file + arguments
Collection<PSObject> results;
// Execute PowerShell script
results = pipeline.Invoke();
//print it in a textbox
AppendLine(results.ToString());

I use like a reference Execute PowerShell Script from C# with Commandline Arguments

the error is "System.Management.Automation.CommandNotFoundException: 'ls .' is not a cmdlet, function or bat file.

Community
  • 1
  • 1
Pablo
  • 17
  • 3

1 Answers1

0

Your expression ls . consists of a command (or rather, an alias) ls and a parameter argument .

The proper way to construct that expression would be:

Command lsCmd = new Command("ls");
lsCmd.Parameters.Add("Path",".");
Pipeline.Commands.Add(lsCmd);
Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206
  • I' going to check like good the answer. But this only resolve partially my problem. Because in a .ps1 script I have the problem to split it to catch the command, and parameters. But you give me a great idea – Pablo Oct 26 '15 at 09:23
  • Use an editor with syntax high-lighting (such as the free PowerShell ISE) to get an idea of how different tokens in your scripts are interpreted. – Mathias R. Jessen Oct 26 '15 at 12:24