How can I pass a cmdlet as a parameter value in C#? In other words, what would the the .NET equivalent of the following be?
PS> Get-Content -Path (Some-Cmdlet)
I have the following code:
var ps = PowerShell.Create(session);
ps.AddComand("Get-Content").AddParameter("Path", "(Some-Cmdlet)");
However, the string "(Some-Cmdlet)" gets passed verbatim. It is not interpreted. I have also tried:
var ps = PowerShell.Create(session);
var cmd = new Command("Some-Cmdlet");
ps.AddComand("Get-Content").AddParameter("Path", cmd);
Unfortunately, it gives the same result. It seems to be calling ToString()
on the Command
object, rather than evaluating it.