question

BohatikovViacheslav avatar image
1 Vote"
BohatikovViacheslav asked BohatikovViacheslav edited

Remove-CalendarEvents cmdlet on Exchange Online throws exception: "String was not recognized as a valid DateTime"!

Seems that problem appears only for Remove-CalendarEvents cmdlet when we set its QueryStartDate parameter.
We have tested Set-Mailbox with StartDateForRetentionHold and EndDateForRetentionHold parameters and Set-MailboxAutoReplyConfiguration with -StartTime and -EndTime and these cmdlets worked just fine. For all cmdlets we have specified dates as object of DateTime type but error appears only for Remove-CalendarEvents.
Problem happens on different time formats, we have tested United Kingdom(dd/MM/yyyy) and Unkrainian(dd.MM.yyyy) date formats that specified in system settings and it seems that problem appears when day part is in the first place. Everything is ok when we using United Sates(M/d/yyyy) format in system settings.

We tried creating dates in different ways:
$date = Get-Date -Date "27.08.2020"
$date = [System.DateTime]::Parse("27.08.2020")
We even tried to specify the kind of days created, but that didn't change anything.

Full error:
Error on proxy command 'Remove-CalendarEvents -Identity:'' -CancelOrganizedMeetings:$True
-Confirm:$False -QueryStartDate:'27/08/2020 00:00:00' -QueryWindowInDays:'1825'' to server
VI1PR06MB5152.eurprd06.prod.outlook.com: Server version 15.20.3999.0000, Proxy method PSWS:
Cmdlet error with following error message:
System.Management.Automation.ParentContainsErrorRecordException: Cannot process argument transformation on parameter
'QueryStartDate'. Cannot convert value "27/08/2020 00:00:00" to type "Microsoft.Exchange.ExchangeSystem.ExDateTime". Error:
"String was not recognized as a valid DateTime.".

Environment:
PSVersion: 5.1.17763.1490
PSEdition: Desktop
PSCompatibleVersions: {1.0, 2.0, 3.0, 4.0...}
BuildVersion: 10.0.17763.1490
CLRVersion: 4.0.30319.42000
WSManStackVersion: 3.0
PSRemotingProtocolVersion: 2.3
SerializationVersion: 1.1.0.1

windows-server-powershelloffice-exchange-online-itpromicrosoft-graph-calendar
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

IanXue-MSFT avatar image
0 Votes"
IanXue-MSFT answered IanXue-MSFT commented

Hi,

Try '08/27/2020 00:00:00' or '2020/08/27 00:00:00' instead of '27/08/2020 00:00:00'. Or you can call the ParseExact method

 $date = [DateTime]::ParseExact('27/08/2020 00:00:00','dd/MM/yyyy hh:mm:ss',[Globalization.CultureInfo]::CreateSpecificCulture('en-GB'))

Best Regards,
Ian Xue
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks for answer but problem is not in creating DateTime object. Problem is with cmdlet that doesn't work properly.

I don't want to use string data representation in cmdlet I want to use a DateTime object which works for all other cases absolutely fine. But even when I set the date in cmdlet as string I've got the same exception no matter which format I am using. But when I change time format in my system settings cmdlet starts working.

0 Votes 0 ·

Does the cmdlet work with the DateTime object $date?

0 Votes 0 ·