Azure に新しくデプロイされた Windows VM でコマンドをリモートで実行する方法を調べていますが、いくつかの基本的な質問があります。
「カスタム スクリプト拡張機能」が答えのようですが、ドキュメントによると、サーバー オペレーティング システムにのみ適用可能であると述べられています。
https://docs.microsoft.com/en-us/azure/virtual-machines/windows/extensions-customscript
これは正しいと思いますか? もしそうなら、サーバー以外の Windows OS はどうですか?
次に、https : //docs.microsoft.com/en-us/azure/virtual-machines/scripts/virtual-にある MS チュートリアルに基づいて、Windows Server 2016 データ センターに対してカスタム スクリプト拡張機能を使用してみました。 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"}
'
これはエラーを返します:
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 でこのアクションを正常に実行するには、追加の手順が必要でしたか?
ありがとう
4c74356b41が言ったように、あなたは、Windows Serverのために、我々は使用する必要があり、Linuxのスクリプトの拡張子を使用しているCustomScriptExtensionをしてpublisher
いるMicrosoft.Compute。
CLI 2.0 を使用して Windows VM に拡張機能を設定できます。私の手順は次の
とおりです。1 .次のように json ファイルを作成します。
{
"commandToExecute": "powershell.exe mkdir C:\\test321"
}
2.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'}"
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加