问题
I am trying to run more than one powershell command(with parameters in each command) in a single .ps1 file.
i.e. In the Azure powershell i need to run these 3 commands sequentially
Set-ExecutionPolicy -Scope LocalMachine -ExecutionPolicy Bypass -Force
Import-AzurePublishSettingsFile
New-AzureService
All the above 3 command receive different parameters. I wanted to keep them in a single .ps1 file.
I am trying as bellow, it is not working although not giving any exception
using (PowerShell ps = PowerShell.Create())
{
string Filepath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"path of .ps1 file");
string Script = File.ReadAllText(Filepath);
IDictionary Param = new Dictionary<String, String>();
Param.Add("–PublishSettingsFile", @"path of pubsetting file");
Param.Add("-ServiceName", CloudServiceName);
Param.Add("-Location", Location);
var result =
PowerShell.Create().AddScript(Script).AddParameters(Param).Invoke();
}
来源:https://stackoverflow.com/questions/28185234/how-to-execute-more-than-one-power-shell-command-in-a-single-ps1-file