如何在 Azure VM(win 7、8、10、服务器)上 运行 部署简单的自定义命令 post?
How to run simple custom commands on a Azure VM (win 7,8,10, Server) post deploy?
我正在研究如何在 Azure 中新部署的 windows VM 上远程 运行 命令,并有几个基本问题。
似乎 'Custom Script Extension' 是答案,但根据文档,声明仅适用于服务器操作系统:
https://docs.microsoft.com/en-us/azure/virtual-machines/windows/extensions-customscript
我认为这是正确的吗?如果是这样,非服务器如何 windows OS?
继续,我尝试根据 MS 教程在 Windows Server 2016 数据中心使用自定义脚本扩展:
https://docs.microsoft.com/en-us/azure/virtual-machines/scripts/virtual-machines-linux-cli-sample-create-vm-nginx?toc=%2fazure%2fvirtual-machines%2flinux%2ftoc.json
我的目标是创建一个新的 Windows VM 并指示它在部署后简单地创建一个新目录。
CLI 步骤:
1. Create a resource group
2. Create a new virtual machine (Server 2016 Datacentre)
3. Finally, run the following command:
az vm extension set --publisher Microsoft.Azure.Extensions --version 2.0 --name CustomScript --vm-name (nameOfMyVM) --resource-group (nameOfMyResourceGroup) --settings '{"commandToExecute":"powershell.exe md c:\testFolder"}
'
这个returns错误:
Handler 'Microsoft.Azure.Extensions.CustomScript' has reported failure for VM Extension 'CustomScript' with terminal error code '1007' and error message: 'Install failed for plugin (name: Microsoft.Azure.Extensions.CustomScript, version 2.0.3) with exception The specified executable is not a valid application for this OS platform.'
是否需要额外的步骤才能在 VM 上成功完成此操作?
谢谢
您正在对 windows 虚拟机使用 Linux 脚本扩展,试试猜猜它有多成功?这是您正在寻找的link:
https://docs.microsoft.com/en-us/azure/virtual-machines/windows/extensions-customscript?toc=%2fazure%2fvirtual-machines%2fwindows%2ftoc.json
此外,自定义脚本扩展是可行的方法,或者您可以使用 DSC 扩展或 Azure 自动化,具体取决于您实际需要的复杂性。
正如 4c74356b41 所说,您正在使用 Linux 脚本扩展,对于 windows 服务器,我们应该使用 CustomScriptExtension 和 publisher
是 Microsoft.Compute.
我们可以使用 CLI 2.0 将扩展设置为 windows VM,这是我的步骤:
1.create 一个 json 文件,像这样:
{
"commandToExecute": "powershell.exe mkdir C:\test321"
}
2.Use CLI 为 windows VM 设置扩展:
我们可以使用这个命令脚本:
az vm extension set -n CustomScriptExtension --publisher Microsoft.Compute --version 1.8 --vm-name jasonvm --resource-group vmm --settings C:\Users\jason\Desktop\test\jasontest5.json
结果如下:
C:\Users\jason>az vm extension set -n CustomScriptExtension --publisher Microsoft.Compute --version 1.8 --vm-name jasonvm --resource-group vmm --settings C:\Users\jason\Desktop\test\jasontest5.json
{
"autoUpgradeMinorVersion": true,
"forceUpdateTag": null,
"id": "/subscriptions/5384xxxx-xxxx-xxxx-xxxx-xxxxe29a7b15/resourceGroups/vmm/providers/Microsoft.Compute/virtualMachines/jasonvm/extensions/CustomScriptExtension",
"instanceView": null,
"location": "centralus",
"name": "CustomScriptExtension",
"protectedSettings": null,
"provisioningState": "Succeeded",
"publisher": "Microsoft.Compute",
"resourceGroup": "vmm",
"settings": {
"commandToExecute": "powershell.exe mkdir C:\test321"
},
"tags": null,
"type": "Microsoft.Compute/virtualMachines/extensions",
"typeHandlerVersion": "1.8",
"virtualMachineExtensionType": "CustomScriptExtension"
}
==========================================
更新:
正如 David 所说,我们可以在没有 json 文件的情况下使用此命令:
az vm extension set -n CustomScriptExtension --publisher Microsoft.Compute --version 1.8 --vm-name DVWinServerVMB --resource-group DVResourceGroup --settings "{'commandToExecute': 'powershell.exe md c:\test'}"
我正在研究如何在 Azure 中新部署的 windows VM 上远程 运行 命令,并有几个基本问题。
似乎 'Custom Script Extension' 是答案,但根据文档,声明仅适用于服务器操作系统:
https://docs.microsoft.com/en-us/azure/virtual-machines/windows/extensions-customscript
我认为这是正确的吗?如果是这样,非服务器如何 windows OS?
继续,我尝试根据 MS 教程在 Windows Server 2016 数据中心使用自定义脚本扩展: https://docs.microsoft.com/en-us/azure/virtual-machines/scripts/virtual-machines-linux-cli-sample-create-vm-nginx?toc=%2fazure%2fvirtual-machines%2flinux%2ftoc.json
我的目标是创建一个新的 Windows VM 并指示它在部署后简单地创建一个新目录。
CLI 步骤:
1. Create a resource group
2. Create a new virtual machine (Server 2016 Datacentre)
3. Finally, run the following command:
az vm extension set --publisher Microsoft.Azure.Extensions --version 2.0 --name CustomScript --vm-name (nameOfMyVM) --resource-group (nameOfMyResourceGroup) --settings '{"commandToExecute":"powershell.exe md c:\testFolder"}
'
这个returns错误:
Handler 'Microsoft.Azure.Extensions.CustomScript' has reported failure for VM Extension 'CustomScript' with terminal error code '1007' and error message: 'Install failed for plugin (name: Microsoft.Azure.Extensions.CustomScript, version 2.0.3) with exception The specified executable is not a valid application for this OS platform.'
是否需要额外的步骤才能在 VM 上成功完成此操作?
谢谢
您正在对 windows 虚拟机使用 Linux 脚本扩展,试试猜猜它有多成功?这是您正在寻找的link:
https://docs.microsoft.com/en-us/azure/virtual-machines/windows/extensions-customscript?toc=%2fazure%2fvirtual-machines%2fwindows%2ftoc.json
此外,自定义脚本扩展是可行的方法,或者您可以使用 DSC 扩展或 Azure 自动化,具体取决于您实际需要的复杂性。
正如 4c74356b41 所说,您正在使用 Linux 脚本扩展,对于 windows 服务器,我们应该使用 CustomScriptExtension 和 publisher
是 Microsoft.Compute.
我们可以使用 CLI 2.0 将扩展设置为 windows VM,这是我的步骤:
1.create 一个 json 文件,像这样:
{
"commandToExecute": "powershell.exe mkdir C:\test321"
}
2.Use CLI 为 windows VM 设置扩展: 我们可以使用这个命令脚本:
az vm extension set -n CustomScriptExtension --publisher Microsoft.Compute --version 1.8 --vm-name jasonvm --resource-group vmm --settings C:\Users\jason\Desktop\test\jasontest5.json
结果如下:
C:\Users\jason>az vm extension set -n CustomScriptExtension --publisher Microsoft.Compute --version 1.8 --vm-name jasonvm --resource-group vmm --settings C:\Users\jason\Desktop\test\jasontest5.json
{
"autoUpgradeMinorVersion": true,
"forceUpdateTag": null,
"id": "/subscriptions/5384xxxx-xxxx-xxxx-xxxx-xxxxe29a7b15/resourceGroups/vmm/providers/Microsoft.Compute/virtualMachines/jasonvm/extensions/CustomScriptExtension",
"instanceView": null,
"location": "centralus",
"name": "CustomScriptExtension",
"protectedSettings": null,
"provisioningState": "Succeeded",
"publisher": "Microsoft.Compute",
"resourceGroup": "vmm",
"settings": {
"commandToExecute": "powershell.exe mkdir C:\test321"
},
"tags": null,
"type": "Microsoft.Compute/virtualMachines/extensions",
"typeHandlerVersion": "1.8",
"virtualMachineExtensionType": "CustomScriptExtension"
}
==========================================
更新:
正如 David 所说,我们可以在没有 json 文件的情况下使用此命令:
az vm extension set -n CustomScriptExtension --publisher Microsoft.Compute --version 1.8 --vm-name DVWinServerVMB --resource-group DVResourceGroup --settings "{'commandToExecute': 'powershell.exe md c:\test'}"