powershell - 使用 Azure 资源管理器时如何获取 CustomScriptExtensions 的输出?

标签 powershell azure azure-resource-manager resourcemanager

我正在使用 Azure PowerShell Runbook 在 Azure 虚拟机上执行 PowerShell 脚本。当我使用 Azure 资源管理器功能时,我找不到获取远程脚本输出的方法,而我必须将其用于部署。有很多使用“非资源管理器”方式的例子,如下所示:

# Execute remote script
$Vm = Get-AzureVM -ServiceName "DSCDemo" -Name "DSCPull"
Set-AzureVMCustomScriptExtension -ContainerName scripts -StorageAccountName psmag -FileName user.ps1 -Run user.ps1 -VM $vm | Update-AzureVM -Verbose
# Get output
$vm = Get-AzureVM -ServiceName DSCDemo -Name DSCPull
$output = $Vm.ResourceExtensionStatusList.ExtensionSettingStatus

$output 变量包含已执行脚本的标准输出和错误输出。对于我的资源管理器版本,相同的代码看起来非常相似:

# Execute remote script
$vm = Get-AzureRmVM -Name "DSCPull" -ResourceGroupName $ResourceGroupName
$result = Set-AzureRmVMCustomScriptExtension -ResourceGroupName $ResourceGroupName `
                                                -VMName "DSCPull"  `
                                                -Name 'user' `
                                                -Location $vm.Location  `
                                                -StorageAccountName psmag  `
                                                -StorageAccountKey '<key>' `
                                                -FileName "user.ps1"  `
                                                -ContainerName "scripts"  `
                                                -RunFile "user.ps1"
$output = Get-AzureRmVM -Name $VMName -ResourceGroupName $ResourceGroupName -Status

但是输出完全不同,我确实找到了包含标准输出或错误输出的任何内容。

如何借助 Azure 资源管理器功能检索输出?

最佳答案

好的,我找到答案了!您始终可以借助 Get-AzureRmVmDiagnosticExtension 命令查询结果:

$output = Get-AzureRmVMDiagnosticsExtension -ResourceGroupName $ResourceGroupName -VMName 'DSCPull' -Name 'user' -Status
$output.SubStatuses[0]
$output.SubStatuses[1]

将返回类似的内容

Code          : ComponentStatus/StdOut/succeeded
Level         : Info
DisplayStatus : Provisioning succeeded
Message       : my output on remote
Time          :


Code          : ComponentStatus/StdErr/succeeded
Level         : Info
DisplayStatus : Provisioning succeeded
Message       :
Time          :

关于powershell - 使用 Azure 资源管理器时如何获取 CustomScriptExtensions 的输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38152873/

相关文章:

Azure管道每个问题

azure - 以非 root 身份运行自定义脚本扩展

java - 如何在服务器上通过 Java 运行 Powershell 命令

azure - 除了贡献者之外,哪些 Azure 角色将允许执行 Add-AzureRmAutoscaleSetting

powershell - 从 PowerShell 输出中删除空格

powershell - REG_BINARY 到 PowerShell 中的 Windows 键

azure - 如何在 Multi-Tenancy Azure B2C 登录页面中允许本地帐户的注册选项?

azure - 将 Azure 保留 IP 映射到云服务端点

powershell - 如何通过 Powershell 为 Azure 配置 github 等

Azure 资源组不可用于已部署的资源