【问题标题】:Azure update management generate patch status report in a csv formatAzure 更新管理以 csv 格式生成补丁状态报告
【发布时间】:2021-05-31 18:33:49
【问题描述】:

我正在创建 Azure 自动化运行手册以生成有关管理组下虚拟机的补丁状态的报告。

使用的查询如下

联合更新,workspace('xxxx').Operation,workspace('yyyy').Operation
|其中 TimeGenerated > ago(10d) |其中分类在(“安全更新”、“关键更新”、“关键和安全更新”)和 ResourceType == “virtualMachines” |按计算机、分类、UpdateState、产品、PublishedDate、MSRCSeverity 汇总更新=makeset(标题) |按 UpdateState 排序

$result = Invoke-AzOperationalInsightsQuery -WorkspaceId $WorkspaceID -Query $query

这里我需要从同一个管理组下的不同订阅中查询日志分析工作区.. 运行方式帐户已在管理组级别将 RBAC 设置为“Log Analytics Reader”。 但查询结果为空记录集,相同查询直接在 Log Analytics 工作区执行时获取记录。

任何关于我在这里缺少的指导都会有很大的帮助。 谢谢

【问题讨论】:

    标签: azure azure-powershell azure-automation azure-log-analytics


    【解决方案1】:

    此命令Invoke-AzOperationalInsightsQuery 只能对一个订阅执行操作,因此在您的情况下,您需要使用循环来设置订阅Set-AzContext -Subscription <subscription-id>,要获取您的 RunAs 帐户可以访问的所有订阅,请使用 @987654324 @。

    示例:

    $connectionName = "AzureRunAsConnection"
    try
    {
        # Get the connection "AzureRunAsConnection "
        $servicePrincipalConnection=Get-AutomationConnection -Name $connectionName         
    
        "Logging in to Azure..."
        Connect-AzAccount `
            -ServicePrincipal `
            -TenantId $servicePrincipalConnection.TenantId `
            -ApplicationId $servicePrincipalConnection.ApplicationId `
            -CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint 
    }
    catch {
        if (!$servicePrincipalConnection)
        {
            $ErrorMessage = "Connection $connectionName not found."
            throw $ErrorMessage
        } else{
            Write-Error -Message $_.Exception
            throw $_.Exception
        }
    }
    
    $query = "xxxxxx"
    $subs = Get-AzSubscription
    foreach($sub in $subs){
        Set-AzContext -Subscription $sub.Id
        #do the things you want e.g. $result = Invoke-AzOperationalInsightsQuery -WorkspaceId $WorkspaceID -Query $query
        
    }
    

    这只是一个示例,要使其工作,还记得在脚本中循环不同的$WorkspaceID

    【讨论】:

    • 您好,如果对您有帮助,请标记为回答,点击i.stack.imgur.com/LkiIZ.png之类的选项即可,谢谢。
    • 谢谢@Joy Wang 它有效。这是我使用的代码。 foreach($subs 中的 $sub){ Set-AzContext -Subscription $sub.Id $WorkspaceID = (Get-AzOperationalInsightsWorkspace).CustomerID foreach($WorkspaceID 中的 $wid){ $query = "xxxxx" $result = Invoke-AzOperationalInsightsQuery - WorkspaceId $wid -Query $query } }
    猜你喜欢
    • 2020-06-28
    • 2019-01-26
    • 1970-01-01
    • 1970-01-01
    • 2023-02-10
    • 2022-01-18
    • 1970-01-01
    • 2017-11-28
    • 1970-01-01
    相关资源
    最近更新 更多