繁体   English   中英

在C#中执行Powershell脚本失败

[英]Executing Powershell Script fails in c#

我的powershell脚本无法运行,并出现以下错误:

码 在此行:-

“ Import-AzureRmContext -Path C:\\ profile.json;”

如果我右键单击该文件,然后单击“使用powershell运行”,则脚本可以正常运行。

如果我使用PowerShellInstance运行,则会出现相同的错误:

在此处输入图片说明

在另一个StackOverflow帖子中找到了此代码。 您可以使用它来通过命令提示符执行Powershell脚本。 使用下面的函数并调用它对我有用:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM