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

Bohatikov Viacheslav 6 Reputation points
2021-04-07T08:34:56.947+00:00

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

Exchange Online
Exchange Online
A cloud-based service included in Microsoft 365, delivering scalable messaging and collaboration features with simplified management and automatic updates.
Windows for business | Windows Server | User experience | PowerShell
Microsoft Security | Microsoft Graph
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. Anonymous
    2021-04-07T09:22:56.227+00:00

    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.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.