Need help on how to export a list of machines on all schedules

Scott Goode 0 Reputation points
2023-01-30T22:23:01.2933333+00:00

Hello,

I have been looking around the internet and I am falling short on how to export a list of all schedules for update manager and the VM's attached to each schedule. I would like to do this with PowerShell but I am open to other ways to accomplish this.

I currently have a script to see all the names of said schedules. This outputs all schedules under the group and account name I use. I need to add to this for the VM' listed in each name.

$a=Get-AzAutomationSchedule -ResourceGroup "Name" -AutomationAccountName "Name"

Get-AzAutomationSchedule -ResourceGroup "Name" -AutomationAccountName "Name"

foreach ($i in $a) {Write-Output $i.Name}

Thank you.

Azure Update Manager
Azure Update Manager
An Azure service to centrally manages updates and compliance at scale.
304 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Jaspreet Singh 6 Reputation points Microsoft Employee
    2023-02-15T17:40:27.6666667+00:00

    Hi Scott,

    You can use these REST APIs to get the list of all the VMs.

    Software Update Configurations - List - REST API (Azure Automation) | Microsoft Learn

    Software Update Configurations - Get By Name - REST API (Azure Automation) | Microsoft Learn

    PS Script:

    $subscriptionId="xxxxxxxxx"
    $resourceGroupName="xxxxxx"
    $automationAccountName="xxxx"
    
    $token="xxxxxxxxxxx"
    
    $headers = @{
        Authorization="Bearer $token"
    }
    
    $BaseUrl = "https://management.azure.com"
    $Uri = "/subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.Automation/automationAccounts/$automationAccountName/softwareUpdateConfigurations"
    $ApiVersion = "?api-version=2019-06-01"
    
    $sucsUrl = $BaseUrl + $Uri + $ApiVersion 
    
    $sucsResponseData = Invoke-RestMethod -Uri $sucsUrl -Method Get -Headers $headers
    
    Write-Output "Total number of SUCs: " $sucsResponseData.value.Count
    
    Foreach ($suc in $sucsResponseData.value) {
        $sucUrl = $BaseUrl + $suc.id + $ApiVersion
        $sucResponseData = Invoke-RestMethod -Uri $sucUrl -Method Get -Headers $headers
    
        Write-Output "SUC name: " $sucResponseData.name
        Write-Output "Azure Virtual Machines: " $sucResponseData.properties.updateConfiguration.azureVirtualMachines
        Write-Output "Non-Azure Computer Names: " $sucResponseData.properties.updateConfiguration.nonAzureComputerNames
        Write-Output "======================" 
    }
    
    
    1 person found this answer helpful.

  2. Monalla-MSFT 12,946 Reputation points
    2023-02-03T15:51:23.1766667+00:00

    @Scott Goode - Welcome to Microsoft Q&A and thanks for reaching out to us.

    Have you tried using Get-AzAutomationSoftwareUpdateConfiguration command. It should help you to retrieve the list of schedules and also the VM's connected to it. You can use for-each loop to identify respective schedules and vm's in each schedule.

    Get-AzAutomationSoftwareUpdateConfiguration
       [-ResourceGroupName] <String>
       [-AutomationAccountName] <String>
       [-DefaultProfile <IAzureContextContainer>]
       [<CommonParameters>]
    

    Hope this helps. and please feel free to reach out if you have any further questions.


    If the above response was helpful, please feel free to "Accept as Answer" and "Upvote" the same so it can be beneficial to the community.


  3. Scott Goode 0 Reputation points
    2023-02-06T22:34:51.9133333+00:00

    Hello Monalla,

    Thank you for the reply. That did help. It seems to be what I need with the exception of NonAzureComputers field is empty for each schedule. I noticed this because the 3 schedules I have in Azure, do in fact have NonAzureComputers attached to them. They have the AUM Agent installed and are working properly per the schedule. They are getting updates properly via the AUM schedule with the on-prem agent.

    Do I need to add something to the script to get this info?

    AZ

    Connect-AzAccount

    Set-AzContext "NAME"

    $a=Get-AzAutomationSoftwareUpdateConfiguration -ResourceGroupName "NAME" -AutomationAccountName "NAME"

    Foreach ($s in $a) {Write-Output $s.Name $s.UpdateConfiguration}

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.