azure-powershell icon indicating copy to clipboard operation
azure-powershell copied to clipboard

Set-AzureRmRecoveryServicesVaultContext is not working in 5.5.0

Open dragonfly91 opened this issue 8 years ago • 10 comments

Description

With the latest update, 5.5.0, Set-AzureRmRecoveryServicesVaultContext cmdlet is not working.

This means that the Set-AzureRmRecoveryServicesVaultContext cmdlet was unable to initialize the Vault parameter correctly. Based on the changeset, this seems to be introduced by some of the changes from the platform team.

One observation is that our internal BVT was not able to catch this issue. BVT runs with the MSI and it is still passing i.e., installation with MSI is passing. However, installation with PowerShellGet is failing.

Mitigation steps for RecoveryServices Backup customers: roll back to 5.4.1.

Script/Steps for Reproduction

> Login-AzureRmAccount
> $vault = Get-AzureRmRecoveryServiceVault -Name vaultName -ResourceGroup vaultRg
> Set-AzureRmRecoveryServicesVaultContext -Vault $vault
> Get-AzureRmRecoveryServicesBackupItem -BackupManagementType AzureVM -WorkloadType AzureVM

ERROR:

Get-AzureRmRecoveryServicesBackupItem : Set vault context first using cmdlet Set-AzureRmRecoveryServicesVaultContext
At line:45 char:16
+ ... ckupitems = Get-AzureRmRecoveryServicesBackupItem -BackupManagementTy ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-AzureRmRecoveryServicesBackupItem], ArgumentException
    + FullyQualifiedErrorId : 
Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.GetAzureRmRecoveryServicesBackupItem

Mitigation Steps

Install using MSI https://github.com/Azure/azure-powershell/releases/download/v5.5.0-March2018/azure-powershell.5.5.0.msi instead of PowerShellGet

Module Version

5.5.0

Environment Data

PS C:\WINDOWS\system32> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.16299.248
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.16299.248
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Debug Output

PS C:\WINDOWS\system32> Get-AzureRmRecoveryServicesBackupItem -WorkloadType AzureVM -BackupManagementType AzureVM
DEBUG: 3:39:03 PM - GetAzureRmRecoveryServicesBackupItem begin processing with ParameterSet 'GetItemsForVault'.
DEBUG: 3:39:03 PM - using account id '[email protected]'...
DEBUG: Inside Restore. Going to create ResourceClient.
DEBUG: [Common.Authentication]: Authenticating using Account: '[email protected]', environment: 'AzureCloud', tenant: '72f988bf-86f1-41af-91ab-2d7cd011db47'
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 :
DEBUG: 03/16/2018 10:09:03: ecf80441-9d98-4c02-a8bf-76d8d414bf3b - AcquireTokenHandlerBase: === Token Acquisition started:
 Authority: https://login.microsoftonline.com/72f988bf-86f1-41af-91ab-2d7cd011db47/
 Resource: https://management.core.windows.net/
 ClientId: 1950a258-227b-4e31-a9cf-717495945fc2
 CacheType: Microsoft.Azure.Commands.Common.Authentication.AuthenticationStoreTokenCache (3 items)
 Authentication Target: User

DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Verbose: 1 :
DEBUG: 03/16/2018 10:09:03: ecf80441-9d98-4c02-a8bf-76d8d414bf3b - TokenCache: Looking up cache for a token...
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 :
DEBUG: 03/16/2018 10:09:03: ecf80441-9d98-4c02-a8bf-76d8d414bf3b - TokenCache: An item matching the requested resource was found in the cache
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Verbose: 1 :
DEBUG: 03/16/2018 10:09:03: ecf80441-9d98-4c02-a8bf-76d8d414bf3b - TokenCache: An expired or near expiry token was found in the cache
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 :
DEBUG: 03/16/2018 10:09:03: ecf80441-9d98-4c02-a8bf-76d8d414bf3b - TokenCache: A matching item (access token or refresh token or both) was found in the cache
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Verbose: 1 :
DEBUG: 03/16/2018 10:09:03: ecf80441-9d98-4c02-a8bf-76d8d414bf3b - <RefreshAccessTokenAsync>d__11: Refreshing access token...
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Verbose: 1 :
DEBUG: 03/16/2018 10:09:05: ecf80441-9d98-4c02-a8bf-76d8d414bf3b - TokenCache: Storing token in the cache...
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Verbose: 1 :
DEBUG: 03/16/2018 10:09:05: ecf80441-9d98-4c02-a8bf-76d8d414bf3b - TokenCache: An item was stored in the cache
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 :
DEBUG: 03/16/2018 10:09:05: ecf80441-9d98-4c02-a8bf-76d8d414bf3b - AcquireTokenHandlerBase: === Token Acquisition finished successfully. An access token was retuned:
 Access Token Hash: IpMLwIvM2QTIclI/3GkSJOb1kOm9bUNLJ9oz7+n+kHI=
 Refresh Token Hash: p70UPaza4L9jgCediqTvStgqnIyYXdyj9F1X214Fw24=
 Expiration Time: 03/16/2018 11:09:04 +00:00
 User Hash: v39LX9ad10kctry0UELeeauwdMKHbDaZgUPfYLoHtDU=

DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 :
DEBUG: 03/16/2018 10:09:05:  - TokenCache: Serializing token cache with 3 items.
DEBUG: Client Created successfully
DEBUG: Caught exception, type: System.ArgumentException
DEBUG: Received ArgumentException
Get-AzureRmRecoveryServicesBackupItem : Set vault context first using cmdlet Set-AzureRmRecoveryServicesVaultContext
At line:1 char:1
+ Get-AzureRmRecoveryServicesBackupItem -WorkloadType AzureVM -BackupMa ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-AzureRmRecoveryServicesBackupItem], ArgumentException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.GetAzureRmRecoveryServicesBackupItem

DEBUG: AzureQoSEvent: CommandName - Get-AzureRmRecoveryServicesBackupItem; IsSuccess - False; Duration - 00:00:01.9720758; Exception - System.ArgumentException: Set vault context first using cmdlet
Set-AzureRmRecoveryServicesVaultContext
   at Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ServiceClientAdapterNS.ClientProxyBase.GetResourceName()
   at Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ServiceClientAdapterNS.ServiceClientAdapter.ListProtectedItem(ODataQuery`1 queryFilter, String skipToken)
   at Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ProviderModel.IaasVmPsBackupProvider.ListProtectedItems()
   at Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.GetAzureRmRecoveryServicesBackupItem.<ExecuteCmdlet>b__26_0()
   at Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.RecoveryServicesBackupCmdletBase.ExecutionBlock(Action action, Boolean shouldProcess);
DEBUG: Finish sending metric.
DEBUG: 3:39:06 PM - GetAzureRmRecoveryServicesBackupItem end processing.
DEBUG: 3:39:06 PM - GetAzureRmRecoveryServicesBackupItem end processing.

dragonfly91 avatar Mar 16 '18 10:03 dragonfly91

@dragonfly91 Working on a fix now, will add you on the review once it is done.

maddieclayton avatar Mar 16 '18 21:03 maddieclayton

I have a similar problem as well. If you try to run through the steps here: https://docs.microsoft.com/en-us/azure/backup/backup-azure-vms-automation then it looks as if the Get-AzureRmRecoveryServicesVault -Name "testvault" | Set-AzureRmRecoveryServicesVaultContext command completes OK, but the next command then fails stating that you first need to set the vault context. Effectively that makes all the following steps null and void and the use of PowerShell with recovery vaults very broken.

I hope the fix comes soon ;-)

digitus0 avatar Mar 19 '18 14:03 digitus0

Closing as fixed as I cannot reproduce the error after the fix linked above. @dragonfly91 please reopen if you continue to see the issue.

maddieclayton avatar Mar 21 '18 18:03 maddieclayton

Hi everyone, Today I faced with the same issue during the working with Set-AzureRmRecoveryServicesVaultContext cmdlet. I have used the same steps for reproduction and implemented the fix provided by @maddieclayton but unfortunately it didn't work out.

leonovss avatar Mar 22 '18 18:03 leonovss

@leonovss The fix will not be released until next Tuesday. In the meantime, you can either downgrade to 5.4.1, or uninstall your modules downloaded using Install-Module, and reinstall using the MSI: https://github.com/Azure/azure-powershell/releases

maddieclayton avatar Mar 22 '18 20:03 maddieclayton

Hi, I am facing the same issue while running cmdlet Get-AzureRmRecoveryServicesBackupProtectionPolicy. Below is the entire error: Get-AzureRmRecoveryServicesBackupProtectionPolicy : Set vault context first using cmdlet Set-AzureRmRecoveryServicesVaultContext At line:1 char:11

  • $policy = Get-AzureRmRecoveryServicesBackupProtectionPolicy -Name 'D ...
  •       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidArgument: (:) [Get-AzureRmReco...rotectionPolicy], ArgumentException
    • FullyQualifiedErrorId : Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.GetAzureRmRecoveryServicesBackupProtectionPolicy

Below are the commands that I used: $recoveryServiceVault = Get-AzureRmRecoveryServicesVault -Name 'RecoveryServiceVaultname'

Set-AzureRmRecoveryServicesVaultContext -Vault $recoveryServiceVault

$policy = Get-AzureRmRecoveryServicesBackupProtectionPolicy -Name 'DefaultPolicy'

chaheti29 avatar Apr 18 '18 10:04 chaheti29

@chaheti29 What version of AzureRM are you currently running? This should be fixed in 5.6.0 and greater.

maddieclayton avatar Apr 18 '18 17:04 maddieclayton

@maddieclayton I am using the latest version 5.7.0. Also AzureRM.RecoveryServices version is 4.1.2 Also I have same version on local powershell and on Azure automation account. It works fine on local but does not return any policy while running runbook in azure automation account.

chaheti29 avatar Apr 19 '18 05:04 chaheti29

@chaheti29 If this is a bug only in automation, please open a new bug (as this issue has been fixed) with the appropriate debug information. Thanks!

maddieclayton avatar Apr 20 '18 20:04 maddieclayton

Hello I did face the same issue with the following version AzureRM.RecoveryServices 4.1.0

Then I upgraded to the following and it's now ok :thumbsup: AzureRM.RecoveryServices 4.1.2 If it can help .. Bye

JamesDLD avatar Apr 27 '18 09:04 JamesDLD