Hi Scripting Guy,
I have been using your blog as reference and working with PowerShell for a while now. I have developed several scripts that handle running external .exe command programs that generate reports. Then, with PowerShell attach those reports to an email (in Outlook), add an HTML body with inline images, generate another report (file) with Excel, also through PowerShell, attach it as well and send it.
Now, I am dealing with scanning the Outlook Inbox for replies to those emails, and it feels like using the Outlook.AdvvanceSearch Method will be a good choice. I have found some samples on the web, but they are all for C# or VBScript. As a matter of fact I used a VBScript as a starting point and I have the following:
Add-Type -Assembly "Microsoft.Office.Interop.Outlook" $ol = New-Object -comObject Outlook.Application $strF = "subject:2015" $strS = "Inbox" # search Inbox and all subfolders $g_InboxSch = $Null #VBScript sample I used as reference #g_InboxSch = g_olApp.AdvancedSearch(Scope:=strS, Filter:=strF, SearchSubFolders:=True, Tag:="Complete") $g_InboxSch = $ol.AdvancedSearch($strS, $strF, $true, "Complete");
However, I get the following error:
Exception calling "AdvancedSearch" with "4" argument(s): "The operation failed." At line:1 char:1 + $g_InboxSch = $ol.AdvancedSearch($strS, $strF, 1, "Complete"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : COMException
I have tried changing the $strS variable to something else, with no luck. I have tried the FolderPath for the actual folder as shown from the output of:
$ol.Session.Folders
Application : Microsoft.Office.Interop.Outlook.ApplicationClass Class : 2 Session : System.__ComObject Parent : System.__ComObject DefaultItemType : 0 DefaultMessageClass : IPM.Note Description : EntryID : #deleted Folders : System.__ComObject Items : System.__ComObject Name : myemail@provider.com StoreID : #deleted UnReadItemCount : 0 UserPermissions : System.__ComObject WebViewOn : True WebViewURL : #res://C:\Program Files\... edited WebViewAllowNavigation : True AddressBookName : ShowAsOutlookAB : False FolderPath : \\myemail@provider.com InAppFolderSyncObject : False CurrentView : System.__ComObject CustomViewsOnly : False Views : System.__ComObject MAPIOBJECT : System.__ComObject FullFolderPath : \\myemail@provider.com IsSharePointFolder : False ShowItemCount : 1 Store : System.__ComObject PropertyAccessor : System.__ComObject UserDefinedProperties : System.__ComObject Application : Microsoft.Office.Interop.Outlook.ApplicationClass Class : 2 Session : System.__ComObject Parent : System.__ComObject DefaultItemType : 6 DefaultMessageClass : IPM.Post Description : EntryID : 000000001A... #edited Folders : System.__ComObject Items : System.__ComObject Name : Public Folders - AaronCalderon@ibc.com StoreID : 0000000... #edited UnReadItemCount : 0 UserPermissions : WebViewOn : False WebViewURL : WebViewAllowNavigation : True AddressBookName : ShowAsOutlookAB : False FolderPath : \\Public Folders - myemail@provider.com InAppFolderSyncObject : False CurrentView : System.__ComObject CustomViewsOnly : False Views : System.__ComObject MAPIOBJECT : System.__ComObject FullFolderPath : \\Public Folders - myemail@provider.com IsSharePointFolder : False ShowItemCount : 0 Store : System.__ComObject PropertyAccessor : System.__ComObject UserDefinedProperties : System.__ComObject Application : Microsoft.Office.Interop.Outlook.ApplicationClass Class : 2 Session : System.__ComObject Parent : System.__ComObject DefaultItemType : 0 DefaultMessageClass : IPM.Note Description : EntryID : 000000005... #edited Folders : System.__ComObject Items : System.__ComObject Name : IBC Payroll Dept StoreID : 00000000... #edited UnReadItemCount : 0 UserPermissions : System.__ComObject WebViewOn : False WebViewURL : WebViewAllowNavigation : True AddressBookName : ShowAsOutlookAB : False FolderPath : \\Company Dept 1 InAppFolderSyncObject : False CurrentView : System.__ComObject CustomViewsOnly : False Views : System.__ComObject MAPIOBJECT : System.__ComObject FullFolderPath : \\Company Dept 1 IsSharePointFolder : False ShowItemCount : 1 Store : System.__ComObject PropertyAccessor : System.__ComObject UserDefinedProperties : System.__ComObject
I wonder if you all have an insight on how to use this Method in PowersShell.
Thanks in advance for your time.
- Edited by Mr. Potter III 12 hours 47 minutes ago Clarify info