Powershell 具有Windows VM和Azure cli:Publisher的Azure自定义脚本扩展无效

Powershell 具有Windows VM和Azure cli:Publisher的Azure自定义脚本扩展无效,powershell,azure,automation,cloud,azure-cli,Powershell,Azure,Automation,Cloud,Azure Cli,我正试图在Azure上配置一些虚拟机,然后立即使用脚本对它们进行自定义。实现这一点的最佳方法似乎是使用自定义脚本扩展 当我尝试在我创建的VM上执行az扩展集时,它会轰炸并抱怨 参数publisher的值无效 这大概是因为我把自己定为出版商。而不是Microsoft.OSTCExtensions或其他一些普遍接受的扩展发布程序 名称Custom Script Extension对我来说意味着可以通过此方法链接加载自定义脚本。如果不先成为扩展发布者,这是不可能的吗 我正在执行的命令: 设置扩展名:

我正试图在Azure上配置一些虚拟机,然后立即使用脚本对它们进行自定义。实现这一点的最佳方法似乎是使用自定义脚本扩展

当我尝试在我创建的VM上执行
az扩展集
时,它会轰炸并抱怨

参数publisher的值无效

这大概是因为我把自己定为出版商。而不是
Microsoft.OSTCExtensions
或其他一些普遍接受的扩展发布程序

名称
Custom Script Extension
对我来说意味着可以通过此方法链接加载自定义脚本。如果不先成为扩展发布者,这是不可能的吗

我正在执行的命令:

设置扩展名:

az vm extension set --resource-group dev-eu2 --vm-name dev-eu2-dc --name deploy_ad_to_eu2.ps1 --publisher "zimmertr" --settings /home/tj/git/Dev.Builder/azure-cli/script_extensions/domain_controller/dc_eu2.json --version v0.1
所述扩展调用的JSON:

{
  "fileUris": ["http://localhost:8000/powershell/domain_controllers/deploy_ad_to_eu2.ps1"],
  "commandToExecute": "./deploy_ad_to_eu2.ps1"
}
这个JSON然后调用
deploy\u ad\u to_eu2.ps1
,这是一个在我的计算机上的文件服务器上运行的Powershell脚本。我知道这个PowerShell脚本100%正常工作,因为我可以将它复制粘贴到PowerShell提示符中,而不会出现任何问题。我只是厌倦了RDPing进入服务器并寻求一点自动化


我在这里做错了什么吗?

发布者指的是扩展本身的发布者,而不是要执行的脚本的发布者。publisher和name的组合可唯一标识要应用于虚拟机的扩展

Microsoft.Compute-CustomScriptExtension
扩展(其中
Microsoft.Compute
是发布者,
CustomScriptExtension
是扩展的名称)是通用的,因为要执行的扩展脚本通过配置提供。因此,不需要为每个脚本发布一个扩展


换句话说,您不应将自己指定为发布者,而应指定扩展的实际发布者,并使用配置指定要执行的脚本。

发布者指的是扩展本身的发布者,而不是要执行的脚本的发布者。publisher和name的组合可唯一标识要应用于虚拟机的扩展

Microsoft.Compute-CustomScriptExtension
扩展(其中
Microsoft.Compute
是发布者,
CustomScriptExtension
是扩展的名称)是通用的,因为要执行的扩展脚本通过配置提供。因此,不需要为每个脚本发布一个扩展


换句话说,您不应该将自己指定为发布者,您应该指定扩展的实际发布者,并使用配置指定要执行的脚本。

正如Johan所说,我们应该使用
Microsoft.compute
作为发布者,并使用
CustomscriptExtension
作为扩展名

顺便说一下,我们应该使用
--version
1.9,json应该是这样的:

{
  "fileUris": ["https://jasonvmdiag956.blob.core.windows.net/jasonvmtest/jason.ps1"],
  "commandToExecute": "powershell.exe ./jason.ps1"
}
az vm extension set --resource-group jasonvm --vm-name jasonvm --name CustomScriptExtension --publisher Microsoft.Compute --settings D:\cert\qq.json --version 1.9
C:\Users>az vm extension set --resource-group jasonvm --vm-name jasonvm --name CustomScriptExtension --publisher Microsoft.Compute --settings D:\cert\qq.json --version 1.9
{| Finished ..
  "autoUpgradeMinorVersion": true,
  "forceUpdateTag": null,
  "id": "/subscriptions/5384xxxx-xxxx-xxxx-xxxx-xxxxe29axxxx/resourceGroups/jasonvm/providers/Microsoft.Compute/virtualMachines/jasonvm/extensions/CustomScriptExtension",
  "instanceView": null,
  "location": "eastus",
  "name": "CustomScriptExtension",
  "protectedSettings": null,
  "provisioningState": "Succeeded",
  "publisher": "Microsoft.Compute",
  "resourceGroup": "jasonvm",
  "settings": {
    "commandToExecute": "powershell.exe ./jason.ps1",
    "fileUris": [
      "https://jasonvmdiag956.blob.core.windows.net/jasonvmtest/jason.ps1"
    ]
  },
  "tags": null,
  "type": "Microsoft.Compute/virtualMachines/extensions",
  "typeHandlerVersion": "1.9",
  "virtualMachineExtensionType": "CustomScriptExtension"
}
我们可以在Azure CLI 2.0中运行此脚本,如下所示:

{
  "fileUris": ["https://jasonvmdiag956.blob.core.windows.net/jasonvmtest/jason.ps1"],
  "commandToExecute": "powershell.exe ./jason.ps1"
}
az vm extension set --resource-group jasonvm --vm-name jasonvm --name CustomScriptExtension --publisher Microsoft.Compute --settings D:\cert\qq.json --version 1.9
C:\Users>az vm extension set --resource-group jasonvm --vm-name jasonvm --name CustomScriptExtension --publisher Microsoft.Compute --settings D:\cert\qq.json --version 1.9
{| Finished ..
  "autoUpgradeMinorVersion": true,
  "forceUpdateTag": null,
  "id": "/subscriptions/5384xxxx-xxxx-xxxx-xxxx-xxxxe29axxxx/resourceGroups/jasonvm/providers/Microsoft.Compute/virtualMachines/jasonvm/extensions/CustomScriptExtension",
  "instanceView": null,
  "location": "eastus",
  "name": "CustomScriptExtension",
  "protectedSettings": null,
  "provisioningState": "Succeeded",
  "publisher": "Microsoft.Compute",
  "resourceGroup": "jasonvm",
  "settings": {
    "commandToExecute": "powershell.exe ./jason.ps1",
    "fileUris": [
      "https://jasonvmdiag956.blob.core.windows.net/jasonvmtest/jason.ps1"
    ]
  },
  "tags": null,
  "type": "Microsoft.Compute/virtualMachines/extensions",
  "typeHandlerVersion": "1.9",
  "virtualMachineExtensionType": "CustomScriptExtension"
}
输出如下所示:

{
  "fileUris": ["https://jasonvmdiag956.blob.core.windows.net/jasonvmtest/jason.ps1"],
  "commandToExecute": "powershell.exe ./jason.ps1"
}
az vm extension set --resource-group jasonvm --vm-name jasonvm --name CustomScriptExtension --publisher Microsoft.Compute --settings D:\cert\qq.json --version 1.9
C:\Users>az vm extension set --resource-group jasonvm --vm-name jasonvm --name CustomScriptExtension --publisher Microsoft.Compute --settings D:\cert\qq.json --version 1.9
{| Finished ..
  "autoUpgradeMinorVersion": true,
  "forceUpdateTag": null,
  "id": "/subscriptions/5384xxxx-xxxx-xxxx-xxxx-xxxxe29axxxx/resourceGroups/jasonvm/providers/Microsoft.Compute/virtualMachines/jasonvm/extensions/CustomScriptExtension",
  "instanceView": null,
  "location": "eastus",
  "name": "CustomScriptExtension",
  "protectedSettings": null,
  "provisioningState": "Succeeded",
  "publisher": "Microsoft.Compute",
  "resourceGroup": "jasonvm",
  "settings": {
    "commandToExecute": "powershell.exe ./jason.ps1",
    "fileUris": [
      "https://jasonvmdiag956.blob.core.windows.net/jasonvmtest/jason.ps1"
    ]
  },
  "tags": null,
  "type": "Microsoft.Compute/virtualMachines/extensions",
  "typeHandlerVersion": "1.9",
  "virtualMachineExtensionType": "CustomScriptExtension"
}

更新:

{
  "fileUris": ["http://localhost:8000/powershell/domain_controllers/deploy_ad_to_eu2.ps1"],
  "commandToExecute": "./deploy_ad_to_eu2.ps1"
}
我在实验室测试了这个PowerShell,它工作正常,以下是我的步骤:
1.将该powershell脚本上载到Azure存储帐户容器(类型:容器):

2.在本地PC中创建json文件

{
  "fileUris": ["https://jasonvmsdiag665.blob.core.windows.net/ps1/installad.ps1"],
  "commandToExecute": "powershell.exe ./installad.ps1"
}
3.在CLI 2.0中运行该脚本:


正如Johan所说,我们应该使用Microsoft.compute作为发布者,并使用
CustomscriptExtension
作为扩展名

顺便说一下,我们应该使用
--version
1.9,json应该是这样的:

{
  "fileUris": ["https://jasonvmdiag956.blob.core.windows.net/jasonvmtest/jason.ps1"],
  "commandToExecute": "powershell.exe ./jason.ps1"
}
az vm extension set --resource-group jasonvm --vm-name jasonvm --name CustomScriptExtension --publisher Microsoft.Compute --settings D:\cert\qq.json --version 1.9
C:\Users>az vm extension set --resource-group jasonvm --vm-name jasonvm --name CustomScriptExtension --publisher Microsoft.Compute --settings D:\cert\qq.json --version 1.9
{| Finished ..
  "autoUpgradeMinorVersion": true,
  "forceUpdateTag": null,
  "id": "/subscriptions/5384xxxx-xxxx-xxxx-xxxx-xxxxe29axxxx/resourceGroups/jasonvm/providers/Microsoft.Compute/virtualMachines/jasonvm/extensions/CustomScriptExtension",
  "instanceView": null,
  "location": "eastus",
  "name": "CustomScriptExtension",
  "protectedSettings": null,
  "provisioningState": "Succeeded",
  "publisher": "Microsoft.Compute",
  "resourceGroup": "jasonvm",
  "settings": {
    "commandToExecute": "powershell.exe ./jason.ps1",
    "fileUris": [
      "https://jasonvmdiag956.blob.core.windows.net/jasonvmtest/jason.ps1"
    ]
  },
  "tags": null,
  "type": "Microsoft.Compute/virtualMachines/extensions",
  "typeHandlerVersion": "1.9",
  "virtualMachineExtensionType": "CustomScriptExtension"
}
我们可以在Azure CLI 2.0中运行此脚本,如下所示:

{
  "fileUris": ["https://jasonvmdiag956.blob.core.windows.net/jasonvmtest/jason.ps1"],
  "commandToExecute": "powershell.exe ./jason.ps1"
}
az vm extension set --resource-group jasonvm --vm-name jasonvm --name CustomScriptExtension --publisher Microsoft.Compute --settings D:\cert\qq.json --version 1.9
C:\Users>az vm extension set --resource-group jasonvm --vm-name jasonvm --name CustomScriptExtension --publisher Microsoft.Compute --settings D:\cert\qq.json --version 1.9
{| Finished ..
  "autoUpgradeMinorVersion": true,
  "forceUpdateTag": null,
  "id": "/subscriptions/5384xxxx-xxxx-xxxx-xxxx-xxxxe29axxxx/resourceGroups/jasonvm/providers/Microsoft.Compute/virtualMachines/jasonvm/extensions/CustomScriptExtension",
  "instanceView": null,
  "location": "eastus",
  "name": "CustomScriptExtension",
  "protectedSettings": null,
  "provisioningState": "Succeeded",
  "publisher": "Microsoft.Compute",
  "resourceGroup": "jasonvm",
  "settings": {
    "commandToExecute": "powershell.exe ./jason.ps1",
    "fileUris": [
      "https://jasonvmdiag956.blob.core.windows.net/jasonvmtest/jason.ps1"
    ]
  },
  "tags": null,
  "type": "Microsoft.Compute/virtualMachines/extensions",
  "typeHandlerVersion": "1.9",
  "virtualMachineExtensionType": "CustomScriptExtension"
}
输出如下所示:

{
  "fileUris": ["https://jasonvmdiag956.blob.core.windows.net/jasonvmtest/jason.ps1"],
  "commandToExecute": "powershell.exe ./jason.ps1"
}
az vm extension set --resource-group jasonvm --vm-name jasonvm --name CustomScriptExtension --publisher Microsoft.Compute --settings D:\cert\qq.json --version 1.9
C:\Users>az vm extension set --resource-group jasonvm --vm-name jasonvm --name CustomScriptExtension --publisher Microsoft.Compute --settings D:\cert\qq.json --version 1.9
{| Finished ..
  "autoUpgradeMinorVersion": true,
  "forceUpdateTag": null,
  "id": "/subscriptions/5384xxxx-xxxx-xxxx-xxxx-xxxxe29axxxx/resourceGroups/jasonvm/providers/Microsoft.Compute/virtualMachines/jasonvm/extensions/CustomScriptExtension",
  "instanceView": null,
  "location": "eastus",
  "name": "CustomScriptExtension",
  "protectedSettings": null,
  "provisioningState": "Succeeded",
  "publisher": "Microsoft.Compute",
  "resourceGroup": "jasonvm",
  "settings": {
    "commandToExecute": "powershell.exe ./jason.ps1",
    "fileUris": [
      "https://jasonvmdiag956.blob.core.windows.net/jasonvmtest/jason.ps1"
    ]
  },
  "tags": null,
  "type": "Microsoft.Compute/virtualMachines/extensions",
  "typeHandlerVersion": "1.9",
  "virtualMachineExtensionType": "CustomScriptExtension"
}

更新:

{
  "fileUris": ["http://localhost:8000/powershell/domain_controllers/deploy_ad_to_eu2.ps1"],
  "commandToExecute": "./deploy_ad_to_eu2.ps1"
}
我在实验室测试了这个PowerShell,它工作正常,以下是我的步骤:
1.将该powershell脚本上载到Azure存储帐户容器(类型:容器):

2.在本地PC中创建json文件

{
  "fileUris": ["https://jasonvmsdiag665.blob.core.windows.net/ps1/installad.ps1"],
  "commandToExecute": "powershell.exe ./installad.ps1"
}
3.在CLI 2.0中运行该脚本:


谢谢你,约翰!我认为问题的真正根源不是将
powershell.exe
作为
commandToExecute
字段的一部分传递。请参阅我对Jason,Johan的回复。它提供了我现在所经历的另一个问题的见解。谢谢你,约翰!我认为问题的真正根源不是将
powershell.exe
作为
commandToExecute
字段的一部分传递。请参阅我对Jason,Johan的回复。它提供了我现在所经历的另一个问题的见解;此对话已结束。评论不用于扩展讨论;这段对话已经结束。