1
votes

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.

1

1 Answers

0
votes

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);