Azure xplat 到 运行 Windows VM 中的 CustomScriptExtension
Azure xplat to run a CustomScriptExtension in a Windows VM
我正在使用以下命令从 azure xplat cli 创建 Windows VM:
azure network vnet create --location "East US" testnet
azure vm create --vm-name xplattest3 --location "East US" --virtual-network-name testnet --rdp 3389 xplattest3 ad072bd3082149369c449ba5832401ae__Windows-Server-Remote-Desktop-Session-Host-on-Windows-Server-2012-R2-20150828-0350 username SAFEpassword!
创建 Windows 虚拟机后,我想执行一个 powershell 脚本来配置服务器。据我了解,这是通过执行 CustomScriptExtension 来完成的。
我找到了几个 PowerShell 示例,但没有找到 Xplat cli 示例。
例如,我想 运行 以下 HelloWorld PowerShell script:
New-Item -ItemType directory -Path C:\HelloWorld
阅读文档后,我应该能够通过执行类似这样的操作来 运行 CustomExtensionScript(以下命令不起作用):
azure vm extension set xplattest3 CustomScriptExtension Microsoft.Compute 1.4 -i '{"URI":["https://gist.githubusercontent.com/tk421/8b7dd37145eaa8f82e2f/raw/36c11aafd3f5d6b4af97aab9ef5303d80e8ab29b/azureCustomScriptExtensionTest"] }'
我认为问题出在参数 -i
上。我无法在 Internet 上找到示例。有一些参考和文档,例如 MSDN and Github,但没有示例。
因此,我的问题是:如何在使用 xplat cli
在 Azure 中创建 Windows VM 后执行 PowerShell
脚本?
请注意,我目前的方法是 CustomScriptExtension
,但是 任何允许 bootstrap 配置脚本的东西 都会被考虑!
编辑 我怎么知道它失败了?
在我 运行 命令之后 azure vm extension ...
:
xplat cli
确认命令已正确执行。
- 根据 MSDN documentation,已创建文件夹
C:\Packages\Plugins\Microsoft.Compute.CustomScriptExtension\
,但没有脚本下载到 C:\Packages\Plugins\Microsoft.Compute.CustomScriptExtension\{version-number}\Downloads\{iteration}
- 文件夹
C:\HelloWorld
没有创建,说明脚本内容还没有执行
- 我找不到任何类型的日志或痕迹来了解发生了什么。有谁知道我在哪里可以找到这些信息?
我阅读MSDN文档后使用的参数(Json)不正确。但是,您可以通过阅读 C# 代码来获得正确参数的线索。
最后的命令是:
azure vm extension set xplattest3 CustomScriptExtension Microsoft.Compute 1.4 -i '{"fileUris":["https://macstoragetest.blob.core.windows.net/testcontainername/createFolder.ps1"], "commandToExecute": "powershell -ExecutionPolicy Unrestricted -file createFolder.ps1" }'
此命令成功创建了 C:\HelloWorld
目录。
注意:我决定将脚本上传到 Azure,因为我 read in a post 并且在强制性文档中。但是我刚刚测试了从 Github 下载原始脚本并且它工作正常,所以我猜文档有点过时了。
编辑:我创建了一篇详细的文章来解释 how to provision windows servers with xplat-cli in Azure。
我正在使用以下命令从 azure xplat cli 创建 Windows VM:
azure network vnet create --location "East US" testnet
azure vm create --vm-name xplattest3 --location "East US" --virtual-network-name testnet --rdp 3389 xplattest3 ad072bd3082149369c449ba5832401ae__Windows-Server-Remote-Desktop-Session-Host-on-Windows-Server-2012-R2-20150828-0350 username SAFEpassword!
创建 Windows 虚拟机后,我想执行一个 powershell 脚本来配置服务器。据我了解,这是通过执行 CustomScriptExtension 来完成的。
我找到了几个 PowerShell 示例,但没有找到 Xplat cli 示例。
例如,我想 运行 以下 HelloWorld PowerShell script:
New-Item -ItemType directory -Path C:\HelloWorld
阅读文档后,我应该能够通过执行类似这样的操作来 运行 CustomExtensionScript(以下命令不起作用):
azure vm extension set xplattest3 CustomScriptExtension Microsoft.Compute 1.4 -i '{"URI":["https://gist.githubusercontent.com/tk421/8b7dd37145eaa8f82e2f/raw/36c11aafd3f5d6b4af97aab9ef5303d80e8ab29b/azureCustomScriptExtensionTest"] }'
我认为问题出在参数 -i
上。我无法在 Internet 上找到示例。有一些参考和文档,例如 MSDN and Github,但没有示例。
因此,我的问题是:如何在使用 xplat cli
在 Azure 中创建 Windows VM 后执行 PowerShell
脚本?
请注意,我目前的方法是 CustomScriptExtension
,但是 任何允许 bootstrap 配置脚本的东西 都会被考虑!
编辑 我怎么知道它失败了?
在我 运行 命令之后 azure vm extension ...
:
xplat cli
确认命令已正确执行。- 根据 MSDN documentation,已创建文件夹
C:\Packages\Plugins\Microsoft.Compute.CustomScriptExtension\
,但没有脚本下载到C:\Packages\Plugins\Microsoft.Compute.CustomScriptExtension\{version-number}\Downloads\{iteration}
- 文件夹
C:\HelloWorld
没有创建,说明脚本内容还没有执行 - 我找不到任何类型的日志或痕迹来了解发生了什么。有谁知道我在哪里可以找到这些信息?
我阅读MSDN文档后使用的参数(Json)不正确。但是,您可以通过阅读 C# 代码来获得正确参数的线索。
最后的命令是:
azure vm extension set xplattest3 CustomScriptExtension Microsoft.Compute 1.4 -i '{"fileUris":["https://macstoragetest.blob.core.windows.net/testcontainername/createFolder.ps1"], "commandToExecute": "powershell -ExecutionPolicy Unrestricted -file createFolder.ps1" }'
此命令成功创建了 C:\HelloWorld
目录。
注意:我决定将脚本上传到 Azure,因为我 read in a post 并且在强制性文档中。但是我刚刚测试了从 Github 下载原始脚本并且它工作正常,所以我猜文档有点过时了。
编辑:我创建了一篇详细的文章来解释 how to provision windows servers with xplat-cli in Azure。