我正在尝试运行 powershell 命令在 AzureVM 上安装 mysql,但我无法成功。
var windowsVmAccessExtensionName = "VMAccessAgent";
var windowsVmAccessExtensionPublisherName = "Microsoft.Compute";
var windowsVmAccessExtensionTypeName = "VMAccessAgent";
var windowsVmAccessExtensionVersionName = "2.3";
var mySqlScriptWindowsInstallCommand = "powershell.exe -ExecutionPolicy Unrestricted -File installMySQL.ps1";
var mySQLWindowsInstallScriptFileUris = new List<string>()
{
"https://raw.githubusercontent.com/Azure/azure-libraries-for-net/master/Samples/Asset/installMySQL.ps1"
};
//azure.VirtualMachines.RunPowerShellScript(rgName, vmName, mySQLWindowsInstallScriptFileUris, asdf);
var windowsVM = azure.VirtualMachines.GetByResourceGroup(rgName, vmName);
windowsVM.Update()
.DefineNewExtension(windowsVmAccessExtensionName)
.WithPublisher(windowsVmAccessExtensionPublisherName)
.WithType(windowsVmAccessExtensionTypeName)
.WithVersion(windowsVmAccessExtensionVersionName)
.WithPublicSetting("fileUris", mySQLWindowsInstallScriptFileUris)
.WithPublicSetting("commandToExecute", mySqlScriptWindowsInstallCommand)
.Attach()
.Apply();
这段代码甚至没有抛出任何错误,当我检查 VM 时,VM 上没有安装任何 mysql 或 choco。
请建议或帮助 Azure Fluent API 在 Azure VM 上执行 powershell 命令。
更新
更新以下能够运行 powershell 脚本的代码。
var scriptUris = new List<string>()
{
"https://raw.githubusercontent.com/Microsoft/dotnet-core-sample-templates/master/dotnet-core-music-windows/scripts/configure-music-app.ps1"
};
var windowsVM = azure.VirtualMachines.GetByResourceGroup(rgName, vmName);
windowsVM.Update()
.UpdateExtension("CustomScriptExtension")
//.WithPublisher(windowsVmAccessExtensionPublisherName)
//.WithType(windowsVmAccessExtensionTypeName)
//.WithVersion(windowsVmAccessExtensionVersionName)
.WithPublicSetting("fileUris", scriptUris)
.WithPublicSetting("commandToExecute", "powershell -ExecutionPolicy Unrestricted -File configure-music-app.ps1")
//.Attach()
//.Apply();
.Parent()
.Apply();
但是,由于某种原因可能是长时间运行的过程,我收到了这个错误:-
发生一个或多个错误。(长时间运行的操作失败,状态为 'Failed'。附加信息:'VM 在处理扩展 'CustomScriptExtension' 时报告失败。错误消息:“完成执行命令”
有关故障排除的更多信息,请访问https://aka.ms/VMExtensionCSEWindowsTroubleshoot