![azure powershell 运行 customscriptextension-powershell 退出代码 1-从 Azure 门户运行](https://linux22.com/image/649901/azure%20powershell%20%E8%BF%90%E8%A1%8C%20customscriptextension-powershell%20%E9%80%80%E5%87%BA%E4%BB%A3%E7%A0%81%201-%E4%BB%8E%20Azure%20%E9%97%A8%E6%88%B7%E8%BF%90%E8%A1%8C.png)
我一直在使用 Microsoft CustomScriptExtension for VMs 来实现 Azure VM 部署的自动化。
http azure.microsoft.com/blog/2014/04/24/automating-vm-customization-tasks-using-custom-script-extension/
CustomScriptExtension 在 Azure 门户中运行良好。我只需单击复选框即可启用它,并指定位于 Azure 存储容器上的 powershell 脚本,它将在启动后在 VM 上运行。它成功退出代码为 0。
我需要的帮助是通过 Azure Powershell 从命令行调用 CustomScriptExtension。我正在使用 azure-xplat-cli 从 CLI 创建 Azure Windows VM,一切正常(从 VM 启动(包括云服务创建和角色创建)、到端点创建、端点 ACL 创建、在 VM 上启用 CustomScriptExtension)。然后,当我尝试使用 Azure Powershell 运行 CustomScriptExtension 时,它失败了。
看起来 CustomScriptExtension 有效,脚本已下载,但退出代码为 1 失败。但是,如果我在命令行上手动运行相同的脚本,它就会成功。
如果没有更详细的错误消息,我似乎无法找到根本原因。
提前致谢,杰夫
以下是通过 Azure Powershell 成功运行与不成功运行的一些日志比较:
对于从 Azure 门户页面启动 w99app11(并且 CustomScriptExtension 有效)。日志如下:
PS C:\WindowsAzure\Logs\Plugins\Microsoft.Compute.CustomScriptExtension\1.1>
cat .\CustomScriptHandler.log
2015-01-14T20:15:48.4897999Z [Info]: Starting IaaS ScriptHandler Extension v1
2015-01-14T20:15:48.5054217Z [Info]: HandlerEnvironment = Version: 1, HandlerEnvironment: [LogFolder: "C:\WindowsAzure\Logs\Plugins\Microsoft.Compute.CustomS
criptExtension\1.1", ConfigFolder: "C:\Packages\Plugins\Microsoft.Compute.CustomScriptExtension\1.1\RuntimeSettings", StatusFolder: "C:\Packages\Plugins\Microso
ft.Compute.CustomScriptExtension\1.1\Status", HeartbeatFile: "C:\Packages\Plugins\Microsoft.Compute.CustomScriptExtension\1.1\Status\HeartBeat.Json"]
2015-01-14T20:15:48.5054217Z [Info]: Installing Handler
2015-01-14T20:15:48.5054217Z [Info]: Handler successfully installed
2015-01-14T20:15:51.6818933Z [Info]: Starting IaaS ScriptHandler Extension
v1
2015-01-14T20:15:51.6818933Z [Info]: HandlerEnvironment = Version: 1, HandlerEnvironment: [LogFolder: "C:\WindowsAzure\Logs\Plugins\Microsoft.Compute.CustomS
criptExtension\1.1", ConfigFolder: "C:\Packages\Plugins\Microsoft.Compute.CustomScriptExtension\1.1\RuntimeSettings", StatusFolder: "C:\Packages\Plugins\Microso
ft.Compute.CustomScriptExtension\1.1\Status", HeartbeatFile: "C:\Packages\Plugins\Microsoft.Compute.CustomScriptExtension\1.1\Status\HeartBeat.Json"]
2015-01-14T20:15:51.6818933Z [Info]: Enabling Handler
2015-01-14T20:15:51.6818933Z [Info]: Handler successfully enabled
2015-01-14T20:15:51.7287562Z [Info]: Loading configuration for sequence number 0
2015-01-14T20:15:51.8284233Z [Info]: HandlerSettings = ProtectedSettingsCertThumbprint: , ProtectedSettings: {}, Public Settings: {FileUris: [https://portalv
hdslqdvg9p4yz1f8.blob.core.windows.net/scripts/bootstrap-ansible.ps1?sv=2014-02-14&sr=b&sig=qOObvkYmT1pZS7tdFbMYPBeGryD76fz7tfsl8kiSCV0%3D&st=2015-01-14T20%3A03
%3A54Z&se=2114-12-21T20%3A05%3A54Z&sp=r], CommandToExecute: powershell.exe -ExecutionPolicy Unrestricted -File bootstrap-ansible.ps1 }
2015-01-14T20:15:51.8440422Z [Info]: Downloading files specified in configuration...
2015-01-14T20:15:51.8909155Z [Info]: DownloadFiles: fileUri = "https://portalvhdslqdvg9p4yz1f8.blob.core.windows.net/scripts/bootstrap-ansible.ps1?sv=2014-02
-14&sr=b&sig=qOObvkYmT1pZS7tdFbMYPBeGryD76fz7tfsl8kiSCV0=&st=2015-01-14T20:03:54Z&se=2114-12-21T20:05:54Z&sp=r", baseUri = "https://portalvhdslqdvg9p4yz1f8.blob
.core.windows.net/"
2015-01-14T20:15:52.2971695Z [Info]: Files downloaded. Asynchronously executing command: 'powershell.exe -ExecutionPolicy Unrestricted -File bootstrap-ansibl
e.ps1 '
2015-01-14T20:15:52.3127877Z [Info]: Command execution task started. Awaiting completion...
2015-01-14T20:16:16.6145937Z [Info]: Command execution finished. Command exited with code: 0
当我从 Azure Powershell 调用 CustomScriptExtension 时,同一个脚本失败并显示退出代码 1。日志如下:注意:CustomScriptExtension 运行成功,脚本已下载并运行,但因退出代码 1 而失败
cd C:\WindowsAzure\Logs\Plugins\Microsoft.Compute.CustomScriptExtension\1.1\
cat .\CustomScriptHandler.log
2015-01-14T19:16:24.4301817Z [Info]: Starting IaaS ScriptHandler Extension v1
2015-01-14T19:16:24.4301817Z [Info]: HandlerEnvironment = Version: 1, HandlerEnvironment: [LogFolder: "C:\WindowsAzure\ Logs\Plugins\Microsoft.Compute.Custom
ScriptExtension\1.1", ConfigFolder: "C:\Packages\Plugins\Microsoft.Compute.CustomScriptExtension\1.1\RuntimeSettings", StatusFolder: "C:\Packages\Plugins\Micros
oft.Compute.CustomScriptExtension\1.1\Status", HeartbeatFile: "C:\Packages\Plugins\Microsoft.Compute.CustomScriptExtension\1.1\Status\HeartBeat.Json"]
2015-01-14T19:16:24.4458090Z [Info]: Enabling Handler
2015-01-14T19:16:24.4458090Z [Info]: Handler successfully enabled
2015-01-14T19:16:24.4458090Z [Info]: Loading configuration for sequence number 2
2015-01-14T19:16:24.4770569Z [Info]: HandlerSettings = ProtectedSettingsCertThumbprint: , ProtectedSettings: {}, Public Settings: {FileUris: [https://portalv
hdslqdvg9p4yz1f8.blob.core.windows.net/scripts/bootstrap-ansible.ps1], CommandToExecute: powershell -ExecutionPolicy Unrestricted -file ./bootstrap-ansible.ps1
}
2015-01-14T19:16:24.4770569Z [Info]: Downloading files specified in configuration...
2015-01-14T19:16:24.5083104Z [Info]: DownloadFiles: fileUri = "https://portalvhdslqdvg9p4yz1f8.blob.core.windows.net/scripts/bootstrap-ansible.ps1", baseUri
="https://portalvhdslqdvg9p4yz1f8.blob.core.windows.net/"
2015-01-14T19:16:24.8823100Z [Info]: Files downloaded. Asynchronously executing command: 'powershell -ExecutionPolicy Unrestricted -file ./bootstrap-ansible.
ps1 '
2015-01-14T19:16:24.8979517Z [Info]: Command execution task started. Awaiting completion...
2015-01-14T19:16:29.7456296Z [Error]: Command execution finished. Command exited with code: 1