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

Unable to use Get-AzRecoveryServicesVaultSettingsFile No explanation of the Certificate Parameter

Open RayBrindley opened this issue 7 years ago • 10 comments

Description

Azure Site Recovery Services examples are incorrect, unable to download the Vault Settings File.

Certificate is a required parameter, but no explanation on what the certificate should be. Parameter type is a String but no clarification of what to enter. Example in documentation therefore does not work

Also if using the parameter -SiteRecovery, it is unable to determine the ParameterSet.

AzureRm did not require the certificate so this has broken existing scripts.

Steps to reproduce

$SR = Get-AzRecoveryServicesVault -Name "TestVault"
Get-AzRecoveryServicesVaultSettingsFile -SiteRecovery -Vault $SR -Path C:\Temp

Environment data

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

Module versions

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     1.4.0      Az.Accounts                         {Disable-AzDataCollection, Disable-AzContextAutosave, Enab...
Script     1.0.1      Az.Aks                              {Get-AzAks, New-AzAks, Remove-AzAks, Import-AzAksCredentia...
Script     1.0.2      Az.AnalysisServices                 {Resume-AzAnalysisServicesServer, Suspend-AzAnalysisServic...
Script     1.0.0      Az.ApiManagement                    {Add-AzApiManagementRegion, Get-AzApiManagementSsoToken, N...
Script     1.0.0      Az.ApplicationInsights              {Get-AzApplicationInsights, New-AzApplicationInsights, Rem...
Script     1.2.0      Az.Automation                       {Get-AzAutomationHybridWorkerGroup, Remove-AzAutomationHyb...
Script     1.1.2      Az.Automation                       {Get-AzAutomationHybridWorkerGroup, Remove-AzAutomationHyb...
Script     1.0.0      Az.Batch                            {Remove-AzBatchAccount, Get-AzBatchAccount, Get-AzBatchAcc...
Script     1.0.0      Az.Billing                          {Get-AzBillingInvoice, Get-AzBillingPeriod, Get-AzEnrollme...
Script     1.1.0      Az.Cdn                              {Get-AzCdnProfile, Get-AzCdnProfileSsoUrl, New-AzCdnProfil...
Script     1.0.1      Az.CognitiveServices                {Get-AzCognitiveServicesAccount, Get-AzCognitiveServicesAc...
Script     1.6.0      Az.Compute                          {Remove-AzAvailabilitySet, Get-AzAvailabilitySet, New-AzAv...
Script     1.5.0      Az.Compute                          {Remove-AzAvailabilitySet, Get-AzAvailabilitySet, New-AzAv...
Script     1.0.0      Az.ContainerInstance                {New-AzContainerGroup, Get-AzContainerGroup, Remove-AzCont...
Script     1.0.1      Az.ContainerRegistry                {New-AzContainerRegistry, Get-AzContainerRegistry, Update-...
Script     1.0.2      Az.DataFactory                      {Set-AzDataFactoryV2, Update-AzDataFactoryV2, Get-AzDataFa...
Script     1.0.0      Az.DataLakeAnalytics                {Get-AzDataLakeAnalyticsDataSource, New-AzDataLakeAnalytic...
Script     1.1.0      Az.DataLakeStore                    {Get-AzDataLakeStoreTrustedIdProvider, Remove-AzDataLakeSt...
Script     1.0.0      Az.DevTestLabs                      {Get-AzDtlAllowedVMSizesPolicy, Get-AzDtlAutoShutdownPolic...
Script     1.0.0      Az.Dns                              {Get-AzDnsRecordSet, New-AzDnsRecordConfig, Remove-AzDnsRe...
Script     1.1.0      Az.EventGrid                        {New-AzEventGridTopic, Get-AzEventGridTopic, Set-AzEventGr...
Script     1.0.1      Az.EventHub                         {New-AzEventHubNamespace, Get-AzEventHubNamespace, Set-AzE...
Script     1.0.0      Az.HDInsight                        {Get-AzHDInsightJob, New-AzHDInsightSqoopJobDefinition, Wa...
Script     1.0.2      Az.IotHub                           {Add-AzIotHubKey, Get-AzIotHubEventHubConsumerGroup, Get-A...
Script     1.1.0      Az.KeyVault                         {Add-AzKeyVaultCertificate, Update-AzKeyVaultCertificate, ...
Script     1.0.2      Az.KeyVault                         {Add-AzKeyVaultCertificate, Update-AzKeyVaultCertificate, ...
Script     1.2.1      Az.LogicApp                         {Get-AzIntegrationAccountAgreement, Get-AzIntegrationAccou...
Script     1.0.0      Az.MachineLearning                  {Move-AzMlCommitmentAssociation, Get-AzMlCommitmentAssocia...
Script     1.0.0      Az.MarketplaceOrdering              {Get-AzMarketplaceTerms, Set-AzMarketplaceTerms}
Script     1.0.0      Az.Media                            {Sync-AzMediaServiceStorageKeys, Set-AzMediaServiceKey, Ge...
Script     1.0.1      Az.Monitor                          {Get-AzMetricDefinition, Get-AzMetric, Remove-AzLogProfile...
Script     1.6.0      Az.Network                          {Add-AzApplicationGatewayAuthenticationCertificate, Get-Az...
Script     1.3.0      Az.Network                          {Add-AzApplicationGatewayAuthenticationCertificate, Get-Az...
Script     1.0.0      Az.NotificationHubs                 {Get-AzNotificationHub, Get-AzNotificationHubAuthorization...
Script     1.1.0      Az.OperationalInsights              {New-AzOperationalInsightsAzureActivityLogDataSource, New-...
Script     1.0.0      Az.PolicyInsights                   {Get-AzPolicyEvent, Get-AzPolicyState, Get-AzPolicyStateSu...
Script     1.0.0      Az.PowerBIEmbedded                  {Remove-AzPowerBIWorkspaceCollection, Get-AzPowerBIWorkspa...
Script     1.2.0      Az.RecoveryServices                 {Get-AzRecoveryServicesBackupProperty, Get-AzRecoveryServi...
Script     1.1.0      Az.RecoveryServices                 {Get-AzRecoveryServicesBackupProperty, Get-AzRecoveryServi...
Script     1.0.0      Az.RedisCache                       {Remove-AzRedisCachePatchSchedule, New-AzRedisCacheSchedul...
Script     1.0.0      Az.Relay                            {New-AzRelayNamespace, Get-AzRelayNamespace, Set-AzRelayNa...
Script     1.2.1      Az.Resources                        {Get-AzProviderOperation, Remove-AzRoleAssignment, Get-AzR...
Script     1.2.0      Az.Resources                        {Get-AzProviderOperation, Remove-AzRoleAssignment, Get-AzR...
Script     1.0.0      Az.ServiceBus                       {New-AzServiceBusNamespace, Get-AzServiceBusNamespace, Set...
Script     1.0.1      Az.ServiceFabric                    {Add-AzServiceFabricApplicationCertificate, Add-AzServiceF...
Script     1.0.2      Az.SignalR                          {New-AzSignalR, Get-AzSignalR, Get-AzSignalRKey, New-AzSig...
Script     1.7.0      Az.Sql                              {Get-AzSqlDatabaseTransparentDataEncryption, Get-AzSqlData...
Script     1.5.0      Az.Sql                              {Get-AzSqlDatabaseTransparentDataEncryption, Get-AzSqlData...
Script     1.1.0      Az.Storage                          {Get-AzStorageAccount, Get-AzStorageAccountKey, New-AzStor...
Script     1.0.3      Az.Storage                          {Get-AzStorageAccount, Get-AzStorageAccountKey, New-AzStor...
Script     1.0.0      Az.StreamAnalytics                  {Get-AzStreamAnalyticsFunction, Get-AzStreamAnalyticsDefau...
Script     1.0.1      Az.TrafficManager                   {Add-AzTrafficManagerCustomHeaderToEndpoint, Remove-AzTraf...
Script     1.1.2      Az.Websites                         {Get-AzAppServicePlan, Set-AzAppServicePlan, New-AzAppServ...
Script     1.1.1      Az.Websites                         {Get-AzAppServicePlan, Set-AzAppServicePlan, New-AzAppServ...

Debug output

DEBUG: Executing cmdlet with SubscriptionId = eee5ecca-32ef-499b-9524-d1d25d4ad2fc, ResourceGroupName = Migration,
ResourceName = OBGAMigration, TargetLocation = C:\Temp
DEBUG: RecoveryService - Going to upload the certificate
DEBUG: [Common.Authentication]: Authenticating using Account: '[email protected]', environment: 'AzureCloud', tenant:
'4ad93bd7-3a1f-49d4-921b-490b02a1b6ee'
DEBUG: [ADAL]: Information: 28/03/2019 4:25:58 AM: e57d35f9-3241-4dab-9868-5aca20587487 - AcquireTokenHandlerBase.cs:
=== Token Acquisition started:
 Authority: https://login.microsoftonline.com/4ad93bd7-3a1f-49d4-921b-490b02a1b6ee/
 Resource: https://management.core.windows.net/
 ClientId: 1950a258-227b-4e31-a9cf-717495945fc2
 CacheType: null
 Authentication Target: User

DEBUG: [ADAL]: Verbose: 28/03/2019 4:25:58 AM: e57d35f9-3241-4dab-9868-5aca20587487 - TokenCache.cs: Looking up cache
for a token...
DEBUG: [ADAL]: Information: 28/03/2019 4:25:58 AM: e57d35f9-3241-4dab-9868-5aca20587487 - TokenCache.cs: An item
matching the requested resource was found in the cache
DEBUG: [ADAL]: Information: 28/03/2019 4:25:58 AM: e57d35f9-3241-4dab-9868-5aca20587487 - TokenCache.cs: An expired or
near expiry token was found in the cache
DEBUG: [ADAL]: Information: 28/03/2019 4:25:58 AM: e57d35f9-3241-4dab-9868-5aca20587487 - TokenCache.cs: A matching
item (access token or refresh token or both) was found in the cache
DEBUG: [ADAL]: Verbose: 28/03/2019 4:25:58 AM: e57d35f9-3241-4dab-9868-5aca20587487 - AcquireTokenHandlerBase.cs:
Refreshing access token...
DEBUG: [ADAL]: Verbose: 28/03/2019 4:25:58 AM: e57d35f9-3241-4dab-9868-5aca20587487 - TokenCache.cs: Storing token in
the cache...
DEBUG: [ADAL]: Verbose: 28/03/2019 4:25:58 AM: e57d35f9-3241-4dab-9868-5aca20587487 - TokenCache.cs: An item was stored
 in the cache
DEBUG: [ADAL]: Information: 28/03/2019 4:25:58 AM: e57d35f9-3241-4dab-9868-5aca20587487 - AcquireTokenHandlerBase.cs:
=== Token Acquisition finished successfully. An access token was retuned:
 Access Token Hash: Eaio7f4MxMs8197R30oWxKwWEgrVIDewWAk1ateMgZE=
 Expiration Time: 28/03/2019 5:25:58 AM +00:00
 User Hash: bDJ1nuO0SH0ph472jBg8dnTPIV7HF4GrUrK85B8xQrk=

DEBUG: [ADAL]: Information: 28/03/2019 4:25:58 AM:  - TokenCache.cs: Serializing token cache with 2 items.
DEBUG: [Common.Authentication]: Authenticating using Account: '[email protected]', environment: 'AzureCloud', tenant:
'4ad93bd7-3a1f-49d4-921b-490b02a1b6ee'
DEBUG: [ADAL]: Information: 28/03/2019 4:25:58 AM: 41c9c191-2af0-4660-8332-dc65c465e1a2 - AcquireTokenHandlerBase.cs:
=== Token Acquisition started:
 Authority: https://login.microsoftonline.com/4ad93bd7-3a1f-49d4-921b-490b02a1b6ee/
 Resource: https://management.core.windows.net/
 ClientId: 1950a258-227b-4e31-a9cf-717495945fc2
 CacheType: null
 Authentication Target: User

DEBUG: [ADAL]: Verbose: 28/03/2019 4:25:58 AM: 41c9c191-2af0-4660-8332-dc65c465e1a2 - TokenCache.cs: Looking up cache
for a token...
DEBUG: [ADAL]: Information: 28/03/2019 4:25:58 AM: 41c9c191-2af0-4660-8332-dc65c465e1a2 - TokenCache.cs: An item
matching the requested resource was found in the cache
DEBUG: [ADAL]: Information: 28/03/2019 4:25:58 AM: 41c9c191-2af0-4660-8332-dc65c465e1a2 - TokenCache.cs: 59.99994962
minutes left until token in cache expires
DEBUG: [ADAL]: Information: 28/03/2019 4:25:58 AM: 41c9c191-2af0-4660-8332-dc65c465e1a2 - TokenCache.cs: A matching
item (access token or refresh token or both) was found in the cache
DEBUG: [ADAL]: Information: 28/03/2019 4:25:58 AM: 41c9c191-2af0-4660-8332-dc65c465e1a2 - AcquireTokenHandlerBase.cs:
=== Token Acquisition finished successfully. An access token was retuned:
 Access Token Hash: Eaio7f4MxMs8197R30oWxKwWEgrVIDewWAk1ateMgZE=
 Expiration Time: 28/03/2019 5:25:58 AM +00:00
 User Hash: bDJ1nuO0SH0ph472jBg8dnTPIV7HF4GrUrK85B8xQrk=

DEBUG: [ADAL]: Information: 28/03/2019 4:25:58 AM:  - TokenCache.cs: Serializing token cache with 2 items.
DEBUG: [ADAL]: Information: 28/03/2019 4:25:58 AM: a522ed16-38a2-4ad2-9985-bdf6e414c44e - AcquireTokenHandlerBase.cs:
=== Token Acquisition started:
 Authority: https://login.microsoftonline.com/4ad93bd7-3a1f-49d4-921b-490b02a1b6ee/
 Resource: https://management.core.windows.net/
 ClientId: 1950a258-227b-4e31-a9cf-717495945fc2
 CacheType: null
 Authentication Target: User

DEBUG: [ADAL]: Verbose: 28/03/2019 4:25:58 AM: a522ed16-38a2-4ad2-9985-bdf6e414c44e - TokenCache.cs: Looking up cache
for a token...
DEBUG: [ADAL]: Information: 28/03/2019 4:25:58 AM: a522ed16-38a2-4ad2-9985-bdf6e414c44e - TokenCache.cs: An item
matching the requested resource was found in the cache
DEBUG: [ADAL]: Information: 28/03/2019 4:25:58 AM: a522ed16-38a2-4ad2-9985-bdf6e414c44e - TokenCache.cs: 59.99984979
minutes left until token in cache expires
DEBUG: [ADAL]: Information: 28/03/2019 4:25:58 AM: a522ed16-38a2-4ad2-9985-bdf6e414c44e - TokenCache.cs: A matching
item (access token or refresh token or both) was found in the cache
DEBUG: [ADAL]: Information: 28/03/2019 4:25:58 AM: a522ed16-38a2-4ad2-9985-bdf6e414c44e - AcquireTokenHandlerBase.cs:
=== Token Acquisition finished successfully. An access token was retuned:
 Access Token Hash: Eaio7f4MxMs8197R30oWxKwWEgrVIDewWAk1ateMgZE=
 Expiration Time: 28/03/2019 5:25:58 AM +00:00
 User Hash: bDJ1nuO0SH0ph472jBg8dnTPIV7HF4GrUrK85B8xQrk=

DEBUG: [ADAL]: Information: 28/03/2019 4:25:58 AM:  - TokenCache.cs: Serializing token cache with 2 items.
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
PUT

Absolute Uri:
https://management.azure.com/Subscriptions/eee5ecca-32ef-499b-9524-d1d25d4ad2fc/resourceGroups/Migration/providers/Micr
osoft.RecoveryServices/vaults/DomainMigration/certificates/DomainMigratione10eee5ecca-32ef-499b-9524-d1d25d4ad2fc-3-28-2019-va
ultcredentials?api-version=2016-06-01

Headers:
x-ms-client-request-id        : fd742a77-5c14-4538-82da-785adb5dce54-2019-03-28 04:25:58Z-P
accept-language               : en-US

Body:
{
  "properties": {
    "authType": "AAD",
    "certificate": "VGVzdA=="
  }
}

DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
InternalServerError

Headers:
Pragma                        : no-cache
X-Content-Type-Options        : nosniff
x-ms-request-id               : f2aff925-6acc-49da-8bc7-7dad6142a6c6
x-ms-client-request-id        : 9c214d4a-6dad-45e8-ba62-55779e15c01e,9c214d4a-6dad-45e8-ba62-55779e15c01e
Strict-Transport-Security     : max-age=31536000; includeSubDomains
x-ms-failure-cause            : service
x-ms-ratelimit-remaining-subscription-writes: 1196
x-ms-correlation-request-id   : f2aff925-6acc-49da-8bc7-7dad6142a6c6
x-ms-routing-request-id       : AUSTRALIASOUTHEAST:20190328T042621Z:f2aff925-6acc-49da-8bc7-7dad6142a6c6
Connection                    : close
Cache-Control                 : no-cache
Date                          : Thu, 28 Mar 2019 04:26:20 GMT
Server                        : Microsoft-IIS/10.0

Body:
{
  "error": {
    "code": "RestApiInternalError",
    "message": "The REST API call encountered an internal error.\r\nWait for a few minutes and then try the operation
again. If the issue persists, please contact Microsoft support.",
    "target": null,
    "details": null,
    "innerError": null
  }
}


Confirm
Unexpected character encountered while parsing value: T. Path '', line 0, position 0.
[Y] Yes  [A] Yes to All  [H] Halt Command  [S] Suspend  [?] Help (default is "Y"): a
Get-AzRecoveryServicesVaultSettingsFile : Unexpected character encountered while parsing value: T. Path '', line 0, position 0.
At line:1 char:1
+ Get-AzRecoveryServicesVaultSettingsFile -Backup -Vault $SR -Path C:\T ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Get-AzRecoveryServicesVaultSettingsFile], JsonReaderException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.RecoveryServices.GetAzureRmRecoveryServicesVaultSettingsFile

DEBUG: AzureQoSEvent: CommandName - Get-AzRecoveryServicesVaultSettingsFile; IsSuccess - False; Duration - 00:01:06.0730251; Exception -
Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: T. Path '', line 0, position 0.
   at Newtonsoft.Json.JsonTextReader.ParseValue()
   at Newtonsoft.Json.JsonReader.ReadForType(JsonContract contract, Boolean hasConverter)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
   at Microsoft.Azure.Commands.RecoveryServices.RecoveryServicesCmdletBase.HandleException(Exception ex)
   at Microsoft.Azure.Commands.RecoveryServices.GetAzureRmRecoveryServicesVaultSettingsFile.ExecuteCmdlet()
   at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord();
DEBUG: Finish sending metric.
DEBUG: 3:27:01 PM - GetAzureRmRecoveryServicesVaultSettingsFile end processing.
DEBUG: 3:27:01 PM - GetAzureRmRecoveryServicesVaultSettingsFile end processing.
PS AsBuilt>

Error output

Get-AzRecoveryServicesVaultSettingsFile : Unexpected character encountered while parsing value: T. Path '', line 0,
position 0.
At line:1 char:1
+ Get-AzRecoveryServicesVaultSettingsFile -Backup -Vault $SR -Path C:\T ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Get-AzRecoveryServicesVaultSettingsFile], JsonReaderException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.RecoveryServices.GetAzureRmRecoveryServicesVaultSettingsFile

RayBrindley avatar Mar 28 '19 04:03 RayBrindley

@viverm can you take a look?

markcowl avatar Mar 29 '19 01:03 markcowl

Same problem here. Documentation is also buggy….

pedrocarvalhoclaranet avatar Apr 08 '19 11:04 pedrocarvalhoclaranet

Managed to solve this issue with the following code....

$dt = $(Get-Date).ToString("M-d-yyyy") $cert = New-SelfSignedCertificate -DnsName $($vault.Name+$subscriptionid+'-'+$dt+'-vaultcredentials') -CertStoreLocation cert:\CurrentUser\My -NotAfter $(Get-Date).AddHours(2) $certficate = [Convert]::ToBase64String($cert.RawData) $VaultFile = Get-AzRecoveryServicesVaultSettingsFile -SiteRecovery -Vault $vault -Certificate $certficate.ToString() Import-AzRecoveryServicesAsrVaultSettingsFile -Path $VaultFile.FilePath $cert | Remove-Item

pedrocarvalhoclaranet avatar Apr 08 '19 14:04 pedrocarvalhoclaranet

Perfect that's what was missing. Thanks @pedrocarvalhoclaranet

RayBrindley avatar Apr 11 '19 02:04 RayBrindley

Set-AzRecoveryServicesAsrVaultContext -vault $vault

will do the same as below

$VaultFile = Get-AzRecoveryServicesVaultSettingsFile -SiteRecovery -Vault $vault -Certificate $certficate.ToString() Import-AzRecoveryServicesAsrVaultSettingsFile -Path $VaultFile.FilePath

viverm avatar Apr 11 '19 05:04 viverm

Thanks for the fixes listed above. The error messages and documentation are no help in troubleshooting this issue. This needs to corrected as any previous scripts using this are now broken.

jlouie1 avatar May 01 '19 20:05 jlouie1

This seems to be an ongoing issue, any signs of a fix?

ONI-Assassin avatar Jun 18 '19 14:06 ONI-Assassin

@ONI-Assassin We are currently reviewing the fix. we will get back on the details. + @punit1396

Rajeswari-Mamilla avatar Jul 10 '20 06:07 Rajeswari-Mamilla

We are tracking this in our backlog and plan to update this by Q4 CY 2020. Bug: https://msazure.visualstudio.com/One/_workitems/edit/7904756

Sharmistha-Rai avatar Sep 02 '20 10:09 Sharmistha-Rai

Please feel free to reopen for any additional queries.

Sharmistha-Rai avatar Sep 02 '20 11:09 Sharmistha-Rai