Hi,
I am attempting to write a piece of script to create conditional formatting rules for user's Outlook.
I have found the MSDN developer reference for the specific object and it includes an example of what I am trying to achieve:
http://msdn.microsoft.com/en-us/library/ff864185(v=office.15).aspx (Sorry link not set up properly because I haven't posted enough to verify my account yet)
Unfortunately the example is in VBScript and I am failing to convert this into Powershell. So far I have got this:
# Import Outlook and get Mail API
Add-Type -assembly "Microsoft.Office.Interop.Outlook"
$Outlook = New-Object -comobject Outlook.Application
# Set Inbox path as variable
$namespace = $Outlook.GetNameSpace("MAPI")
$inbox = $namespace.GetDefaultFolder([Microsoft.Office.Interop.Outlook.OlDefaultFolders]::olFolderInbox)
$View = $namespace.GetDefaultFolder([Microsoft.Office.Interop.Outlook.OlDefaultFolders]::olFolderInbox).Views
$View.Add("Test", [Microsoft.Office.Interop.Outlook.OlViewType]::olTableView)I know that it works up to the last line, if I print out $View then I can see all of my current views however the final line throws up this error message:
Exception calling "Add" with "2" argument(s): "Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))"
At C:\Scripts\Work_In_Progress\WIP-Outlook_Conditional_Formatting.ps1:11 char:1+ $View.Add("Test", [Microsoft.Office.Interop.Outlook.OlViewType]::olTableView)+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException+ FullyQualifiedErrorId : ComMethodTargetInvocationAny help in working out how to make this work would be much appreciated.
Thank you