[英]Run a Powershell script inside of a C# project
So I want to run a powershell script inside of a c# project.所以我想在 c# 项目中运行 powershell 脚本。 The powershell file would be located in a folder inside the project. powershell 文件将位于项目内的文件夹中。 I am just not sure how to reference that file from c# to run it.我只是不确定如何从 c# 引用该文件来运行它。
Please do a google search before you ask here在这里提问之前请先进行谷歌搜索
https://docs.microsoft.com/da-dk/archive/blogs/kebab/executing-powershell-scripts-from-c https://docs.microsoft.com/da-dk/archive/blogs/kebab/executing-powershell-scripts-from-c
https://duanenewman.net/blog/post/running-powershell-scripts-from-csharp/ https://duanenewman.net/blog/post/running-powershell-scripts-from-csharp/
var ps1File = @"C:\my script folder\script.ps1";
var startInfo = new ProcessStartInfo()
{
FileName = "powershell.exe",
Arguments = $"-NoProfile -ExecutionPolicy unrestricted -file \"{ps1File}\"",
UseShellExecute = false
};
Process.Start(startInfo);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.