Solved

Create Outlook "Rules And Alerts" with Powershell

Posted on 2010-11-10
7
2,399 Views
1 Endorsement
Last Modified: 2012-05-10
Hi,
I'm trying to figure out how to create new message rules in Outlook using Powershell 2.0.  I've tested this in both 2007 and 2010, and can't get it to work.

I am referring to the script
CreateOutLookRule.ps1
http://blogs.technet.com/b/heyscriptingguy/archive/2009/12/16/hey-scripting-guy-december-16-2009.aspx

It fails at the line:
$MoveRuleAction.Folder = $Movetarget

with the error:
Exception setting "Folder": "Cannot convert the "System.__ComObject" value of type "System.__ComObject#{00063006-0000-0000-c000-000000000046}" to type "Microsoft.Office.Interop.Outlook.MAPIFolder"."

Even at the top of this article he talks about how people were getting type mismatch errors.

I also tried the script at this link and get the same type mismatch error:
http://www.eggheadcafe.com/software/aspnet/29542597/can-not-convert-systemcomobject-to-microsoftofficeinteropoutlookmapifolder.aspx

Both issues seem to currently be unresolved.

Can anyone see if they can test these two scripts and come up with a solution?

Thanks,
Jamie
1
Comment
Question by:jamorlando
  • 5
  • 2
7 Comments
 
LVL 5

Expert Comment

by:daveTechSearch
Comment Utility
Just looking at the first link (hey scripting guy). I'm using Outlook 2010.
Looking at this line:
$MoveTarget = $inbox.Folders.item("bob")
Run the script once (get errors, etc), then enter:
$inbox.Folders | get-member
I don't see a property or method called "item".
0
 

Author Comment

by:jamorlando
Comment Utility
Dave, but if after that you were to run:
$inbox.Folders.item("bob") | fl

It returns data ... presumably the folder data.
0
 
LVL 5

Expert Comment

by:daveTechSearch
Comment Utility
you are correct. Odd. It should just work...
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

Author Comment

by:jamorlando
Comment Utility
It seems to work for some, but not for others.

To clarify my original question, I just need a way to script out adding new rules.
Even if there was a way to do this from the Exchange side of things, that would be acceptable.

I'm surprised there aren't more article about this online.
0
 

Author Comment

by:jamorlando
Comment Utility
Referring to the CreateOutLookRule.ps1 script:

If you run:
$namespace.GetType

You can see the type is NameSpaceClass

In the code, there is the line:
$inbox = $namespace.getDefaultFolder($olFolders::olFolderInbox)

According to MSDN, this records type Microsoft.Office.Interop.Outlook.MAPIFolder
http://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook.namespaceclass.getdefaultfolder.aspx

However when I run:
$inbox.GetType()

I see the non-descript __ComObject type, which I believe is the root of the problem.

Can any hardcore PowerShell nerds jump in and help me out?
I've only been dabbling in PS for a couple months.

Thanks,
0
 

Accepted Solution

by:
jamorlando earned 0 total points
Comment Utility
0
 

Author Closing Comment

by:jamorlando
Comment Utility
Other thread solved my problem.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
A procedure for exporting installed hotfix details of remote computers using powershell
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now