Solved

Create Outlook "Rules And Alerts" with Powershell

Posted on 2010-11-10
7
2,560 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 
LVL 5

Expert Comment

by:daveTechSearch
ID: 34105522
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
ID: 34105548
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
ID: 34105907
you are correct. Odd. It should just work...
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jamorlando
ID: 34105938
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
ID: 34116112
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
ID: 34135957
0
 

Author Closing Comment

by:jamorlando
ID: 34178979
Other thread solved my problem.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This article will help to fix the below errors for MS Exchange Server 2013 I. Certificate error "name on the security certificate is invalid or does not match the name of the site" II. Out of Office not working III. Make Internal URLs and Externa…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

726 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