c# run command in powershell code example
Example 1: cmd run powershell command
powershell -ExecutionPolicy Bypass -Command "your script here"
Example 2: c# powershell commandlet
using System.Management.Automation;
namespace SendGreeting
{
[Cmdlet(VerbsCommunications.Send, "Greeting")]
public class SendGreetingCommand : Cmdlet
{
[Parameter(Mandatory=true)]
public string Name
{
get { return name; }
set { name = value; }
}
private string name;
protected override void ProcessRecord()
{
WriteObject("Hello " + name + "!");
}
}
}