Skip to content

Instantly share code, notes, and snippets.

@DavideDunne
Created August 17, 2023 04:38
Show Gist options
  • Save DavideDunne/55d5d01b387035607054ee27d67980be to your computer and use it in GitHub Desktop.
Save DavideDunne/55d5d01b387035607054ee27d67980be to your computer and use it in GitHub Desktop.
Run powershell commands from C#
using System.Management.Automation; // https://www.nuget.org/packages/System.Management.Automation/
using Microsoft.PowerShell; // https://www.nuget.org/packages/Microsoft.PowerShell.SDK/
namespace PowershellCSGist
{
internal class Program
{
static void Main()
{
PowerShell ps = PowerShell.Create();
ps.AddScript("New-Item file.txt"); // Create a text file inside bin folder
ps.Invoke();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment