部署后如何在Azure VM(win 7,8,10,Server)上运行简单的自定义命令? [英] How to run simple custom commands on a Azure VM (win 7,8,10, Server) post deploy?

查看:71
本文介绍了部署后如何在Azure VM(win 7,8,10,Server)上运行简单的自定义命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究如何在Azure中新部署的Windows VM上远程运行命令,并且有一些基本问题.

I'm looking into how I can run commands remotely on a freshly deployed windows VM in Azure, and have a few basic questions.

自定义脚本扩展名"似乎是答案,但根据文档,该声明仅适用于Server操作系统:

It seems like the 'Custom Script Extension' is the answer, but according to the documentation, is stated as only applicable for Server operating systems:

https://docs.microsoft.com/en-us/azure/virtual-machines/windows/extensions-customscript

我认为这是正确的吗?如果是这样,那么非服务器Windows操作系统又如何呢?

This is correct I assume? And if so, what about non-server windows OS?

继续,我已尝试根据Windows上的MS教程针对Windows Server 2016数据中心使用自定义脚本扩展:

Moving on, I have tried using the Custom Script Extension against a Windows Server 2016 data centre, based on the MS tutorial at: 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,并指示它在部署后仅创建一个新的目录.

My aim was to create a new Windows VM and instruct it to simply create a new dir after deployment.

CLI步骤:

1. Create a resource group
2. Create a new virtual machine (Server 2016 Datacentre) 
3. Finally, run the following command:

az vm扩展集--publisher Microsoft.Azure.Extensions --version 2.0 --name CustomScript --vm-name(nameOfMyVM)--resource-group(nameOfMyResourceGroup)--settings'{"commandToExecute":"powershell.exe md c:\ testFolder"} '

这将返回错误:

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上完成此操作?

Should extra steps have been involved to accomplish this action on the VM successfully?

谢谢

推荐答案

正如4c74356b41所说,您正在使用Linux脚本扩展,对于Windows服务器,我们应该使用 CustomScriptExtension publisher Microsoft.Compute .

As 4c74356b41 said, you are using a Linux Script extension, for windows server, we should use CustomScriptExtension and the publisher is Microsoft.Compute.

我们可以使用CLI 2.0将扩展名设置为Windows VM,这是我的步骤:
1.创建一个json文件,像这样:

We can use CLI 2.0 to set extension to windows VM, here are my steps:
1.create a json file, like this:

{
  "commandToExecute": "powershell.exe mkdir C:\\test321"
}

2.使用CLI设置Windows VM的扩展名:我们可以使用以下命令脚本:

2.Use CLI to set extension for windows VM: we can use this command script:

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"
}

======================================== <=>
更新:

==========================================
Update:

正如David所说,我们可以在不使用json文件的情况下使用此命令:

As David said, we can use this command without json file:

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 VM(win 7,8,10,Server)上运行简单的自定义命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆