简体   繁体   中英

Create MSOutlook Com-Object and make it visible

I would like to start MS Outlook for automation and make it visible. I'm typing command:

(new-object -com Outlook.Application).GetNamespace("MAPI").GetDefaultFolder("olFolderInbox").GetExplorer().Display()

Which throws error:

Exception setting "GetDefaultFolder": Cannot convert the "olFolderInbox" value of type "string" to type "Object".
At line:1 char:1
+ (new-object -com Outlook.Application).GetNamespace("MAPI").GetDefault ...

This doesn't work too:

$Outlook = New-Object -ComObject Outlook.Application 
$Outlook.visible = $True

Spoiler: This works:

(new-object -com Outlook.Application).GetNamespace("MAPI").GetDefaultFolder([Microsoft.Office.Interop.Outlook.OlDefaultFolders]::olFolderInbox).GetExplorer().Display()

The NameSpace.GetDefaultFolder method takes the type of default folder to return represented by the OlDefaultFolders enumeration (numeric values).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM