如何使用 New-AzConfigurationAssignment Powershell cmdlet 实现不同订阅的动态范围 -Azure 更新管理器

问题描述 投票:0回答:1

我无法使用 Powershell 为与 VM (InGuestPatching) 相关的维护配置设置动态范围。我已经创建了维护配置。现在,我想在订阅级别动态范围内使用 powershell 对大量虚拟机进行配置分配。但 powershell cmdlet 无法做到这一点。

Import-Module Az.Accounts
Import-Module Az.Resources
Import-Module Az.Compute
Import-Module Az.Automation
Import-Module Az.Storage
Import-Module Az.KeyVault
Import-Module Az.Maintenance
Import-Module Az.Compute  

Set-AzContext -Subscription ""

$maintenanceconfig =  New-AzMaintenanceConfiguration -ResourceGroup $RGName -Name $configName -MaintenanceScope $scope -Location $location -StartDateTime $startDateTime -TimeZone $timeZone -Duration $duration -RecurEvery $recurEvery -WindowParameterClassificationToInclude $WindowsParameterClassificationToInclude -InstallPatchRebootSetting $RebootOption -ExtensionProperty @{"InGuestPatchMode"="User"}     

New-AzConfigurationAssignment -ConfigurationAssignmentName $maintenanceconfig.Name -MaintenanceConfigurationId $maintenanceconfig.Id -ProviderName Microsoft.Compute -ResourceType virtualMachines -FilterLocation eastus2 -FilterOsType Windows -FilterOperator "Any" -FilterTag '{"network_environment" : ["sb"]}'

上面的代码无法创建动态作用域分配,下面是我收到的错误。

错误

我不知道我到底错过了什么,但这个 cmdlet 对我不起作用,并且 MS 文档缺少该信息。请提出解决方案

azure powershell patch azure-virtual-machine azure-update-management-center
1个回答
0
投票

如何使用 New-AzConfigurationAssignment Powershell cmdlet 实现不同订阅的动态范围 -Azure 更新管理器。

这里是更新的 PowerShell 脚本,用于为 VM 创建维护配置。

    $RGName           = "RG-Name"
    $configName        = "workervmscentralus"
    $scope            = "InGuestPatch"
    $location         = "eastus2euap"
    $startDateTime    = "2024-03-09 12:30"
    $timeZone         = "UTC"
    $duration         = "3:00"
    $recurEvery       = "Day"
    $WindowsParameterClassificationToInclud = "apt","httpd"
    $RebootOption = "IfRequired"
    $Flocation  =  "eastus2euap,centraluseuap"
    $maintenanceconfig = New-AzMaintenanceConfiguration -ResourceGroupName v-nehrujir-Mindtree `
    -Name workervmseastus `
    -MaintenanceScope "InGuestPatch" `
    -Location eastus2 `
    -Timezone "UTC" `
    -StartDateTime "2025-10-09 12:30" `
    -Duration "3:00" `
    -RecurEvery "Day" `
    -LinuxParameterPackageNameMaskToInclude "apt","httpd" `
    -ExtensionProperty @{inGuestPatchMode="User"} `
    -InstallPatchRebootSetting "IfRequired" `
    
    
  $assignment = New-AzConfigurationAssignment -ResourceGroup $RGName -ResourceName "testvm" -ConfigurationAssignmentName $maintenanceconfig.Name -MaintenanceConfigurationId $maintenanceconfig.Id -ProviderName Microsoft.Compute -ResourceType virtualMachines -FilterLocation eastus2  -FilterOsType Windows -FilterOperator "Any" -FilterTag '{"network_environment" : ["sb"]}' -Location centralus
    
 $assignment = New-AzConfigurationAssignment -ResourceGroup $RGName -ResourceName testvm -ConfigurationAssignmentName $maintenanceconfig.Name -MaintenanceConfigurationId $maintenanceconfig.Id -ProviderName Microsoft.Compute -ResourceType virtualMachines -FilterLocation eastus2 -FilterOsType Windows -FilterOperator "Any" -FilterTag '{"network_environment" : ["sb"]}' -Location centralus

输出:

enter image description here

参考: New-AzConfigurationAssignment

© www.soinside.com 2019 - 2024. All rights reserved.