Created
August 17, 2023 04:38
-
-
Save DavideDunne/55d5d01b387035607054ee27d67980be to your computer and use it in GitHub Desktop.
Run powershell commands from C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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