简体   繁体   中英

Executing Powershell Script fails in c#

My powershell script fails to run with the following error:

码 On this line: -

"Import-AzureRmContext -Path C:\\profile.json;"

If I right click the file and "Run with powershell" then the script runs fine.

If I run using PowerShellInstance, get the same error:

在此处输入图片说明

Found this code from another StackOverflow Post. Which you can use to execute powershell scripts using command prompt. 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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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