Is there any script/command which will give patch status of virtual machines from selective subscriptions.

Diptesh Kumar 101 Reputation points
2024-04-14T08:58:11.4166667+00:00

Is there any script/command which will give patch status of VMs from selective subscriptions. I am looking for CSV file.

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

1 answer

Sort by: Most helpful
  1. Patchfox 3,786 Reputation points
    2024-04-15T04:26:56.3966667+00:00

    Hi Diptesh Kumar

    you can use PowerShell. Below are the steps to achieve this:

    1. Connect to Your Azure Account: Open a PowerShell window. Run the following command to sign in to your Azure account:
           Connect-AzAccount
           
      
    2. Set the Subscription Context: Replace 'your_subscription_id' with your actual subscription ID. Run the following command to set the subscription context:
           Set-AzContext -Subscription [ID]
           
      
    3. Get All VMs in the Subscription: Run the following command to retrieve all VMs in the subscription:
           $vms =  Get-AzVM
           
      
    4. Loop Through Each VM and Run the Script: Example loop:
           foreach ( $vm in $vms) 
         {
         $VMPatchResult = Invoke-AzVMPatchAssessment -ResourceGroupName $vm.ResourceGroupName            -VMName  $vm
          VMPatchAssessment += $VMPatchResult
         $VMPatchAssessment Export-Csv -Path .\Processes.csv 
           
           }
          $VMPatchAssessment | Export-Csv -Path [PATH]
      
    5. Export the Results: You can export the results to a CSV file or any other format you prefer.

    If the reply was helpful, please don’t forget to upvote or accept it as an answer, thank you!