Skip to content

C# | System.Management.Automation

Get the current date and time.

public class Program
{
static void Main()
{
// create empty pipeline
PowerShell ps = PowerShell.Create();
// add command
ps.AddCommand("Get-Date");
// run command(s)
Console.WriteLine("Date: {0}", ps.Invoke().First());
Console.ReadLine();
}
}

enter image description here

The **System.Management.Automation** namespace is the root namespace for Windows PowerShell.

System.Management.Automation is an extension library from Microsoft and it can be added to Visual Studio projects via NuGet package manager or package manager console.

nuget-ui

PM> Install-Package System.Management.Automation