I am trying to get calendar items from a shared calendar through Powershell with the following code:
$outlook = new-object -ComObject Outlook.application $session = $outlook.Session $session.Logon("Outlook") $namespace = $outlook.GetNamespace("MAPI") $recipient = $namespace.CreateRecipient("John Smith") $theirCalendar = $namespace.GetSharedDefaultFolder($recipient, "olFolderCalendar")
but I get a type mismatch error:
Cannot convert argument "0" with value: "System .__ ComObject", for "GetSharedDefaultFolder" enter "Microsoft.Office.I nterop.Outlook.Recipient": "Cannot convert value" System .__ ComObject "to type" System .__ ComObject # {00063045-0000-00 00-c000-000000000046} "to print" Microsoft.Office.Interop.Outlook.Recipient "." On line: 1 char: 34 + $ namespace.GetSharedDefaultFolder <<<($ recipient, "olFolderCalendar") + CategoryInfo: NotSpecified: (:) [], MethodException + FullyQualifiedErrorId: MethodArgumentConversionInvalidCastArgument
I tried pouring $ recipient directly into Microsoft.Office.Interop.Outlook.Recipient , which does not work, and I also tried the invoke-method() procedure, well described here: http://www.mcleod.co.uk/scotty/ powershell / COMinterop.htm
It seems that the latter should work, but it does not seem to have provisions for the many parameters that GetSharedDefaultFolder() requires.
source share