I am trying to scrape specific emails to automatically create calendar appointments. I’m having trouble setting the start time for each appointment.
The code boils down to the following. As you can see, the data types appear to be the same, but I’m getting a data type mismatch error.
What Powershell or Outlook nuance have I missed?
$olFolderCalendar = 9
$Outlook = New-Object -ComObject Outlook.Application
$namespace = $Outlook.GetNameSpace("MAPI")
$calendar = $namespace.GetDefaultFolder($olFolderCalendar)
$StartDate = Get-Date -Date "Monday, June 17, 2024 11:00 pm"
Write-Host $StartDate.GetType()
$appt = $calendar.Items.Add()
Write-Host $appt.Start.GetType()
$appt.Duration = 60
$appt.Start = $s.StartDate
System.DateTime
System.DateTime
OperationStopped: untitled:Untitled-10:14:1
Line |
14 | $appt.Start = $s.StartDate
| ~~~~~~~~~~~~~~~~~~~~~~~~~~
| Unable to cast object of type 'System.DateTime' to type 'System.String'.