Hi Team, I am trying to add resources in Maintenance Configurations in Azure Update Manager using PowerShell using the following Script -
# Install the Az.Maintenance module if you haven't already
Install-Module -Name Az.Maintenance -Force
# Authenticate to Azure
Connect-AzAccount
Set-AzContext -SubscriptionId $subscriptionId
# Variables
$resourceGroupName = "yourResourceGroupName"
$maintenanceConfigName = "yourMaintenanceConfigName"
$location = "yourLocation" # Azure region for the Maintenance Configuration (e.g., "eastus")
$vmResourceGroupName = "yourVMResourceGroupName" # Resource group containing the VMs
$subscriptionId = "yourSubscriptionId" # Your Azure subscription ID
# List of VM names to add
$vmList = @("VM1", "VM2", "VM3")
# Create the maintenance configuration (Guest Scope for patching inside VMs)
New-AzMaintenanceConfiguration `
-ResourceGroupName $resourceGroupName `
-Name $maintenanceConfigName `
-MaintenanceScope "Guest" `
-Location $location `
-Force
# Get the created configuration (to get its ID)
$maintenanceConfiguration = Get-AzMaintenanceConfiguration -ResourceGroupName $resourceGroupName -Name $maintenanceConfigName
# Loop through VMs and add them to the configuration
foreach ($vmName in $vmList) {
New-AzConfigurationAssignment `
-ResourceGroupName $vmResourceGroupName `
-Location $location `
-ResourceName $vmName `
-ResourceType "VirtualMachines" `
-ProviderName "Microsoft.Compute" `
-ConfigurationAssignmentName "VMMaintenanceAssignment" `
-MaintenanceConfigurationId $maintenanceConfiguration.Id
}
Write-Host "Maintenance configuration created and VMs added."
But I am getting the following error -
The Error - "The resource type could not be found in the namespace "Microsoft.HybridCompute" for api version '2023-09-01-preview'."
Or
The Error - "The resource type could not be found in the namespace "Microsoft.Compute" for api version '2023-09-01-preview'."