Azure / Azure/azure-powershell
Register-AzRecoveryServicesBackupContainer (BackupManagementType limited to AzureWorkloads)
- Dominant language
- C#
- Stars
- 4.8k
- Forks
- 4.3k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 51
Description
### Description
When using the Register-AzRecoveryServicesBackupContainer cmdlet, to register an AzureVM container the cmdlet is limited to a BackupManagementType of AzureWorkloads. The documentation states that the available workload types are AzureVM, AzureSQLDatabase, AzureFiles, MSSQL however when the cmdlet runs the error Register-AzRecoveryServicesBackupContainer: BackupManagementType is not expected for WorkloadType: AzureVM is produced. If the WorkloadType parameter is not supplied the cmdlet asks for input. If the WorkloadType is set to AzureVM as is accepted by Get-AzRecoveryServicesBackupItem, the response is as follows "The argument "AzureVM" does not belong to the set "AzureWorkload" specified by the ValidateSet attribute." Was this cmdlet intended for use with Azure VMs?
Steps to reproduce the issue.
Run the following cmdlet:
```ps
Register-AzRecoveryServicesBackupContainer -ResourceId "/subscriptions//resourceGroups//providers/Microsoft.Compute/virtualMachines/TestVM" `
-VaultId "/subscriptions//resourceGroups//providers/Microsoft.RecoveryServices/vaults/emcvault" -WorkloadType AzureVM -BackupManagementType AzureWorkload -Debug
```
### Issue script & Debug output
```ps
Register-AzRecoveryServicesBackupContainer -ResourceId "/subscriptions//resourceGroups//providers/Microsoft.Compute/virtualMachines/TestVM" `
-VaultId "/subscriptions//resourceGroups//providers/Microsoft.RecoveryServices/vaults/emcvault" -WorkloadType AzureVM -BackupManagementType AzureWorkload -Debug
```
```PowerShell
Debug output:
DEBUG: 12:46:54 PM - RegisterAzureRmRecoveryServicesBackupContainer begin processing with ParameterSet 'Register'.
DEBUG: 12:46:54 PM - using account id 'username'...
DEBUG: 12:46:54 PM - [ConfigManager] Got nothing from [DisplayBreakingChangeWarning], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: Inside Restore. Going to create ResourceClient.
DEBUG: [Common.Authentication]: Authenticating using Account: 'username', environment: 'AzureUSGovernment', tenant: 'tenantid'
DEBUG: 12:46:54 PM - [ConfigManager] Got nothing from [EnableLoginByWam], Module = [], Cmdlet = []. Returning default value [False].
DEBUG: 12:46:54 PM - [SilentAuthenticator] Calling SharedTokenCacheCredential.GetTokenAsync - TenantId:'tenantid', Scopes:'https://management.core.usgovcloudapi.net//.default', AuthorityHost:'https://login.microsoftonline.us/', UserId:'username'
DEBUG: SharedTokenCacheCredential.GetToken invoked. Scopes: [ https://management.core.usgovcloudapi.net//.default ] ParentRequestId:
DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.5 Microsoft Windows 10.0.22621 [2023-06-27 17:46:54Z - bc49f967-a9e4-4611-99c3-2b2e6ca68775] IsLegacyAdalCacheEnabled: yes
DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.5 Microsoft Windows 10.0.22621 [2023-06-27 17:46:54Z - bc49f967-a9e4-4611-99c3-2b2e6ca68775] [Region discovery] Not using a regional authority.
DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.5 Microsoft Windows 10.0.22621 [2023-06-27 17:46:54Z - bc49f967-a9e4-4611-99c3-2b2e6ca68775] [Region discovery] Not using a regional authority.
DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.5 Microsoft Windows 10.0.22621 [2023-06-27 17:46:54Z - bc49f967-a9e4-4611-99c3-2b2e6ca68775] [Region discovery] Not using a regional authority.
DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.5 Microsoft Windows 10.0.22621 [2023-06-27 17:46:54Z - bc49f967-a9e4-4611-99c3-2b2e6ca68775] [Region discovery] Not using a regional authority.
DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.5 Microsoft Windows 10.0.22621 [2023-06-27 17:46:54Z - bc49f967-a9e4-4611-99c3-2b2e6ca68775] IsLegacyAdalCacheEnabled: yes
DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.5 Microsoft Windows 10.0.22621 [2023-06-27 17:46:54Z - bc49f967-a9e4-4611-99c3-2b2e6ca68775] IsLegacyAdalCacheEnabled: yes
DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.5 Microsoft Windows 10.0.22621 [2023-06-27 17:46:54Z] Found 3 cache accounts and 0 broker accounts
DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.5 Microsoft Windows 10.0.22621 [2023-06-27 17:46:54Z] Returning 3 accounts
DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.5 Microsoft Windows 10.0.22621 [2023-06-27 17:46:54Z - ec24745e-2dcc-473a-a505-7e366ed9db00] MSAL MSAL.NetCore with assembly version '4.49.1.0'. CorrelationId(ec24745e-2dcc-473a-a505-7e366ed9db00)
DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.5 Microsoft Windows 10.0.22621 [2023-06-27 17:46:54Z - ec24745e-2dcc-473a-a505-7e366ed9db00] === AcquireTokenSilent Parameters ===
DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.5 Microsoft Windows 10.0.22621 [2023-06-27 17:46:54Z - ec24745e-2dcc-473a-a505-7e366ed9db00] LoginHint provided: False
DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.5 Microsoft Windows 10.0.22621 [2023-06-27 17:46:54Z - ec24745e-2dcc-473a-a505-7e366ed9db00] Account provided: True
DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.5 Microsoft Windows 10.0.22621 [2023-06-27 17:46:54Z - ec24745e-2dcc-473a-a505-7e366ed9db00] ForceRefresh: False
DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.5 Microsoft Windows 10.0.22621 [2023-06-27 17:46:54Z - ec24745e-2dcc-473a-a505-7e366ed9db00]
=== Request Data ===
Authority Provided? - True
Scopes - https://management.core.usgovcloudapi.net//.default
Extra Query Params Keys (space separated) -
ApiId - AcquireTokenSilent
IsConfidentialClient - False
SendX5C - False
LoginHint ? False
IsBrokerConfigured - False
HomeAccountId - False
CorrelationId - ec24745e-2dcc-473a-a505-7e366ed9db00
UserAssertion set: False
LongRunningOboCacheKey set: False
Region configured:
DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.5 Microsoft Windows 10.0.22621 [2023-06-27 17:46:54Z - ec24745e-2dcc-473a-a505-7e366ed9db00] === Token Acquisition (SilentRequest) started:
Scopes: https://management.core.usgovcloudapi.net//.default
Authority Host: login.microsoftonline.us
DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.5 Microsoft Windows 10.0.22621 [2023-06-27 17:46:54Z - ec24745e-2dcc-473a-a505-7e366ed9db00] [Region discovery] Not using a regional authority.
DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.5 Microsoft Windows 10.0.22621 [2023-06-27 17:46:54Z - ec24745e-2dcc-473a-a505-7e366ed9db00] Access token is not expired. Returning the found cache entry. [Current time (06/27/2023 17:46:54) - Expiration Time (06/27/2023 18:39:46 +00:00) - Extended Expiration Time (06/27/2023 18:39:46 +00:00)]
DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.5 Microsoft Windows 10.0.22621 [2023-06-27 17:46:54Z - ec24745e-2dcc-473a-a505-7e366ed9db00] Returning access token found in cache. RefreshOn exists ? False
DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.5 Microsoft Windows 10.0.22621 [2023-06-27 17:46:54Z - ec24745e-2dcc-473a-a505-7e366ed9db00] [Region discovery] Not using a regional authority.
DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.5 Microsoft Windows 10.0.22621 [2023-06-27 17:46:54Z - ec24745e-2dcc-473a-a505-7e366ed9db00]
=== Token Acquisition finished successfully:
DEBUG: False MSAL 4.49.1.0 MSAL.NetCore .NET 7.0.5 Microsoft Windows 10.0.22621 [2023-06-27 17:46:54Z - ec24745e-2dcc-473a-a505-7e366ed9db00] AT expiration time: 6/27/2023 6:39:46 PM +00:00, scopes: https://management.core.usgovcloudapi.net//user_impersonation https://management.core.usgovcloudapi.net//.default. source: Cache
DEBUG: SharedTokenCacheCredential.GetToken succeeded. Scopes: [ https://management.core.usgovcloudapi.net//.default ] ParentRequestId: ExpiresOn: 2023-06-27T18:39:46.0000000+00:00
DEBUG: [Common.Authentication]: Received token with LoginType 'User', Tenant: 'tenantid', UserId: 'username'
DEBUG: Client Created successfully
Confirm
Are you sure you want to perform this action?
Performing the operation "Register" on target "/subscriptions/test-sub/resourceGroups/rgtest/providers/Microsoft.Compute/virtualMachines/TestVM".
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): Y
Confirm
Are you sure you want to perform this action?
Performing the operation "Registering container" on target "TestVM".
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): Y
Confirm
Are you sure you want to register the container 'TestVM'
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): Y
DEBUG: Caught exception, type: System.ArgumentException
DEBUG: Received ArgumentException
DEBUG: 12:47:08 PM - [ConfigManager] Got [True] from [EnableDataCollection], Module = [], Cmdlet = [].
Register-AzRecoveryServicesBackupContainer: BackupManagementType is not expected for WorkloadType: AzureVM
DEBUG: 12:47:08 PM - [ConfigManager] Got nothing from [DisplayBreakingChangeWarning], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: 12:47:08 PM - [ConfigManager] Got nothing from [DisplayRegionIdentified], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: AzureQoSEvent: Module: Az.RecoveryServices:6.1.2; CommandName: Register-AzRecoveryServicesBackupContainer; PSVersion: 7.3.4; IsSuccess: False; Duration: 00:00:04.0279108; Exception: BackupManagementType is not expected for WorkloadType: AzureVM;
DEBUG: 12:47:08 PM - RegisterAzureRmRecoveryServicesBackupContainer end processing.
```
### Environment data
```PowerShell
Name Value
---- -----
PSVersion 7.3.4
PSEdition Core
GitCommitId 7.3.4
OS Microsoft Windows 10.0.22621
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
```
### Module versions
```PowerShell
ModuleType Version PreRelease Name ExportedCommands
---------- ------- ---------- ---- ----------------
Script 2.12.1 Az.Accounts {Add-AzEnvironment, Clear-AzConfig, Clear-AzContext, Clear-AzDefault…}
Script 5.2.0 Az.Compute {Add-AzImageDataDisk, Add-AzVhd, Add-AzVMAdditionalUnattendContent, Add-AzVMDataDisk…}
Script 6.1.2 Az.RecoveryServices {Add-AzRecoveryServicesAsrReplicationProtectedItemDisk, Backup-AzRecoveryServicesBackupItem, Copy-AzRecoveryServicesVault, Disable-AzRecoveryS…
```
### Error output
```PowerShell
HistoryId: 100
Message : BackupManagementType is not expected for WorkloadType: AzureVM
StackTrace : at Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ProviderModel.PsBackupProviderManager.GetProviderInstance(WorkloadType workloadType, Nullable`1 backupManagementType)
at Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.RegisterAzureRmRecoveryServicesBackupContainer.<>c__DisplayClass24_0.b__1()
at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ConfirmAction(Boolean force, String continueMessage, String processMessage, String target, Action action, Func`1 useShouldContinue)
at Microsoft.Azure.Commands.ResourceManager.Common.AzureRMCmdlet.ConfirmAction(Boolean force, String continueMessage, String processMessage, String target, Action action)
at Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.RegisterAzureRmRecoveryServicesBackupContainer.b__24_0()
at Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.RecoveryServicesBackupCmdletBase.ExecutionBlock(Action action, Boolean shouldProcess)
Exception : System.ArgumentException
InvocationInfo : {Register-AzRecoveryServicesBackupContainer}
Line : Register-AzRecoveryServicesBackupContainer -ResourceId "/subscriptions/subid/resourceGroups/rgname/providers/Microsoft.Compute/virtualMachines/TestVM" `
Position : At line:1 char:1
+ Register-AzRecoveryServicesBackupContainer -ResourceId "/subscription …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 100
```
Contributor guide
Research direction
Start at RegisterAzureRmRecoveryServicesBackupContainer and the GetProviderInstance call named in the stack trace; inspect how WorkloadType AzureVM and BackupManagementType AzureWorkload are validated and mapped. Done means the reproduced command no longer rejects the documented Azure VM registration path, or the supported parameter combination is clarified and behaves consistently.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, csharp, powershell
- Domain
- cli, cloud
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100