1 つの .ps1 ファイルで複数の powershell コマンド (各コマンドにパラメーターを指定) を実行しようとしています。
つまり、Azure PowerShell では、これら 3 つのコマンドを順番に実行する必要があります。
Set-ExecutionPolicy -Scope LocalMachine -ExecutionPolicy Bypass -Force
Import-AzurePublishSettingsFile
New-AzureService
上記の 3 つのコマンドはすべて、異なるパラメーターを受け取ります。それらを単一の .ps1 ファイルに保持したかったのです。
私は次のようにしようとしていますが、例外はありませんが機能していません
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();
}