[英]Executing Powershell Script fails in c#
My powershell script fails to run with the following error: 我的powershell脚本无法运行,并出现以下错误:
"Import-AzureRmContext -Path C:\\profile.json;" “ Import-AzureRmContext -Path C:\\ profile.json;”
If I right click the file and "Run with powershell" then the script runs fine. 如果我右键单击该文件,然后单击“使用powershell运行”,则脚本可以正常运行。
If I run using PowerShellInstance, get the same error: 如果我使用PowerShellInstance运行,则会出现相同的错误:
Found this code from another StackOverflow Post. 在另一个StackOverflow帖子中找到了此代码。 Which you can use to execute powershell scripts using command prompt.
您可以使用它来通过命令提示符执行Powershell脚本。 This worked for me using the below function and call:
使用下面的函数并调用它对我有用:
ExecuteCommand("powershell -command \" & C:\\PowershellFileName.ps1\"");
public void ExecuteCommand(string Command)
{
ProcessStartInfo ProcessInfo;
Process Process;
ProcessInfo = new ProcessStartInfo("cmd.exe", "/K " + Command);
ProcessInfo.CreateNoWindow = true;
ProcessInfo.UseShellExecute = true;
Process = Process.Start(ProcessInfo);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.