![](/img/trans.png)
[英]ARM - How to pass a parameter to commandToExecute with spaces?
[英]Bicep/ARM - How to use commandToExecute with powershell commands?
我想在 Windows VM 上使用自定義腳本擴展在部署后自動運行兩個 powershell 命令。 我嘗試使用以下擴展名: https ://docs.microsoft.com/en-us/azure/virtual-machines/extensions/custom-script-windows 但在"commandToExecute"
中,我想直接輸入兩個 powershell 命令和不是通過 .ps1 文件。
二頭肌代碼如下:
resource extension 'Microsoft.Compute/virtualMachines/extensions@2021-11-01' = {
parent: windowsvm
name:'config-app'
location:location
properties:{
publisher: 'Microsoft.Compute'
type:'CustomScriptExtension'
typeHandlerVersion: '1.10'
autoUpgradeMinorVersion: true
protectedSettings:{
commandToExecute: 'powershell -command "Install-Module -Name XXXX -AllowClobber -Force; Install-Module -Name XXXX -AllowClobber -Scope CurrentUser -Force"'
}
}
}
但部署目前處於無限循環中。 有什么想法可以直接傳遞這兩個命令嗎?
謝謝!
由於大多數 powershell 命令都是以 powershell 腳本的形式運行的,在 bicep/ARM 模板中具有 .ps1 文件擴展名,因此部署將成功,因為我們的本地機器已經在機器中安裝了 powershell 模塊。
與 Azure VM 中一樣,默認情況下可能不存在 nuget。 因此,正如 AzUser1 所述,可能需要安裝所需的 nuget 才能直接在模板中使用命令。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.