C# Language

System.Management.Automation

Remarks#

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

Invoke simple synchronous pipeline

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


This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow