Azure / azure-powershell

Microsoft Azure PowerShell
Other
4.26k stars 3.86k forks source link

Get-AzureRmRecoveryServicesAsrEvent - String was not recognized as a valid DateTime #6293

Closed AndyHerb closed 5 years ago

AndyHerb commented 6 years ago

Description

Get-AzureRmRecoveryServicesAsrEvents appears not to work when you provide a value for the StartTime or EndTime parameters. This appears to be the case whether a text date is provided, or a datetime object.

Script/Steps for Reproduction

$RsvName = 'YourRecoveryServicesVault'
$RSV = Get-AzureRmRecoveryServicesVault -Name $RsvName
$FilePath = Get-AzureRmRecoveryServicesVaultSettingsFile -Vault $RSV
Import-AzureRmRecoveryServicesAsrVaultSettingsFile -Path $FilePath.FilePath
$Date = Get-Date
Get-AzureRmRecoveryServicesAsrEvent -StartTime $Date

Module Version

AzureRM 6.1.0

Environment Data

PSVersion 5.1.17134.48 PSEdition Desktop PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...} BuildVersion 10.0.17134.48 CLRVersion 4.0.30319.42000 WSManStackVersion 3.0 PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1

Debug Output

DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
GET

Absolute Uri:
https://management.azure.com/Subscriptions/<SubscriptionId>/resourceGroups/<ResourceGroup>/prov
iders/Microsoft.RecoveryServices/vaults/<RecoveryServicesVaultName>/replicationEvents?$filter=StartTime eq '23/05/2018 00:00:00'
and EndTime eq '24/05/2018 00:00:00'&api-version=2016-08-10

Headers:
x-ms-client-request-id        : a977ec04-1674-4446-b665-5ce7e8f0a270-2018-05-24 15:52:03Z-Ps
accept-language               : en-US
Agent-Authentication          :
{"NotBeforeTimestamp":"\/Date(1527173523910)\/","NotAfterTimestamp":"\/Date(1527778323910)\/","ClientRequestId":"a977ec
04-1674-4446-b665-5ce7e8f0a270-2018-05-24
15:52:03Z-Ps","HashFunction":"HMACSHA256","Hmac":"eCh7KoGVraK52sUdzHsIljGGmeQ91mhizSdS7xv6Pqs=","Version":{"Major":1,"M
inor":2,"Build":-1,"Revision":-1,"MajorRevision":-1,"MinorRevision":-1},"PropertyBag":{}}

Body:

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

Status Code:
BadRequest

Headers:
Pragma                        : no-cache
Strict-Transport-Security     : max-age=31536000; includeSubDomains
Cache-Control                 : no-cache
Server                        : Microsoft-IIS/8.0,Microsoft-IIS/10.0
X-AspNet-Version              : 4.0.30319
X-Powered-By                  : ASP.NET
X-Content-Type-Options        : nosniff
x-ms-request-id               : 5fe502c1-a45b-4dd3-96be-af520ea5039c
x-ms-client-request-id        : c13e1388-7b44-4bf8-b7a8-7499b9b6fea7
x-ms-ratelimit-remaining-subscription-reads: 14994
x-ms-correlation-request-id   : 5fe502c1-a45b-4dd3-96be-af520ea5039c
x-ms-routing-request-id       : UKWEST:20180524T155203Z:5fe502c1-a45b-4dd3-96be-af520ea5039c
Date                          : Thu, 24 May 2018 15:52:02 GMT

Body:
{
  "error": {
    "code": "BadRequest",
    "message": "String was not recognized as a valid DateTime.",
    "details": [
      {
        "code": "UnhandledException",
        "message": "String was not recognized as a valid DateTime.",
        "clientRequestId": "c13e1388-7b44-4bf8-b7a8-7499b9b6fea7",
        "activityId": "5fe502c1-a45b-4dd3-96be-af520ea5039c"
      }
    ]
  }
}

Get-AzureRmRecoveryServicesAsrEvent : Operation Failed.
ErrorCode: UnhandledException
Message: String was not recognized as a valid DateTime.
ClientRequestId: c13e1388-7b44-4bf8-b7a8-7499b9b6fea7
ActivityId: 5fe502c1-a45b-4dd3-96be-af520ea5039c
At line:11 char:1
+ Get-AzureRmRecoveryServicesAsrEvent -StartTime $Date -EndTime $Date.A ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Get-AzureRmRecoveryServicesAsrEvent], InvalidOperationException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.RecoveryServices.SiteRecovery.GetAzureRmRecoveryServicesAsrEven
   ts

DEBUG: AzureQoSEvent: CommandName - Get-AzureRmRecoveryServicesAsrEvent; IsSuccess - False; Duration -
00:00:00.6780091; Exception - System.InvalidOperationException: Operation Failed.
ErrorCode: UnhandledException
Message: String was not recognized as a valid DateTime.
ClientRequestId: c13e1388-7b44-4bf8-b7a8-7499b9b6fea7
ActivityId: 5fe502c1-a45b-4dd3-96be-af520ea5039c

   at Microsoft.Azure.Commands.RecoveryServices.SiteRecovery.SiteRecoveryCmdletBase.HandleException(Exception ex)
   at Microsoft.Azure.Commands.RecoveryServices.SiteRecovery.SiteRecoveryCmdletBase.ExecuteCmdlet()
   at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord();

Resolve-AzureRmError Output

Message        : Operation Failed.
                 ErrorCode: UnhandledException
                 Message: String was not recognized as a valid DateTime.
                 ClientRequestId: c13e1388-7b44-4bf8-b7a8-7499b9b6fea7
                 ActivityId: 5fe502c1-a45b-4dd3-96be-af520ea5039c

StackTrace     :    at Microsoft.Azure.Commands.RecoveryServices.SiteRecovery.SiteRecoveryCmdletBase.HandleException(Exception ex)
                    at Microsoft.Azure.Commands.RecoveryServices.SiteRecovery.SiteRecoveryCmdletBase.ExecuteCmdlet()
                    at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
Exception      : System.InvalidOperationException
InvocationInfo : {Get-AzureRmRecoveryServicesAsrEvent}
Line           : Get-AzureRmRecoveryServicesAsrEvent -StartTime $Date -EndTime $Date.AddDays(1)
Position       : At line:11 char:1
                 + Get-AzureRmRecoveryServicesAsrEvent -StartTime $Date -EndTime $Date.A ...
                 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : 3
cormacpayne commented 6 years ago

@viverm Hey Vipin, would you mind taking a look at this issue?

viverm commented 6 years ago

looking in it.

viverm commented 6 years ago

hi AndyHerb

can you try passing the date in string "MM/dd/yyyy hh:mm:ss AM"

PS C:\Users\viverm> Get-AzureRmRecoveryServicesAsrEvent -StartTime "5/18/2018 2:05:00 AM" -EndTime "5/23/2018 2:21:47 PM"| select TimeOfOccurence,eventCode

TimeOfOccurence EventCode


5/23/2018 2:01:00 PM EA0430 5/23/2018 1:24:27 PM EA0431 5/23/2018 12:58:55 PM EA0430 5/23/2018 12:23:23 PM EA0431 5/23/2018 12:06:46 PM InMageCommon_ECH0003 5/23/2018 12:06:17 PM SRSMasterTargetHealthChanged 5/23/2018 11:50:37 AM InMageCommon_ECH0003 5/23/2018 11:50:37 AM InMageCommon_ECH0001 5/23/2018 11:50:37 AM InMageCommon_ECH0007 5/23/2018 11:50:25 AM InMageCommon_ECH0001 5/23/2018 11:49:57 AM SRSMasterTargetHealthChanged 5/23/2018 11:49:57 AM MasterTargetMobilityAgentServiceHeartbeat 5/23/2018 11:26:09 AM EA0430 5/23/2018 10:50:43 AM EA0431 5/23/2018 10:23:35 AM SRSDRAHeartbeatMissing

AndyHerb commented 6 years ago

That doesn't seem to have resolved anything unfortunately

PS C:\> $DebugPreference = "Continue"
PS C:\> Get-AzureRmRecoveryServicesAsrEvent -StartTime "5/18/2018 2:05:00 AM" -EndTime "5/23/2018 2:21:47 PM" -Debug
Get-AzureRmRecoveryServicesAsrEvent : Cannot bind parameter 'StartTime'. Cannot convert value "5/18/2018 2:05:00 AM" to type "System.DateTime". Error: "String was not recognized as a valid DateTime."
At line:1 char:48
+ ... eRmRecoveryServicesAsrEvent -StartTime "5/18/2018 2:05:00 AM" -EndTim ...
+                                            ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-AzureRmRecoveryServicesAsrEvent], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.Azure.Commands.RecoveryServices.SiteRecovery.GetAzureRmRecoveryServicesAsrEvents

Interestingly, the below does work:

PS C:\> [datetime]"5/18/2018 2:05:00 AM"
18 May 2018 02:05:00
viverm commented 6 years ago

@cormacpayne can you help with this . Autoboxing of date from above "5/18/2018 2:05:00 AM" is not happening in andyherb's PS but working fine in mine

$PSVersionTable.psVersion 5.1.17134.228

Rajeswari-Mamilla commented 5 years ago

Closing as the issue could not be reproduced and there has been no activity for the past 1 year