Solved

Create Outlook "Rules And Alerts" with Powershell

Posted on 2010-11-10
7
2,538 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
To Patch or not to Patch? That is the question!

Don't get caught out like thousands of others around the world in the recent Ransomware Fiasco!
Discuss..
- Why it's not a good idea to wait before Patching
- Sensible approaches to Patching discussed
- Add your feedback, comments and suggestions

 

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

Increase your protection from Zero Day threats!

Running two Antivirus' is never a good idea.
Taking advantage of Multiple Security layers on the other hand can often save your hide.
See which top notch security software brands have been proven to happily coexist together.
Reduce your chances of becoming a statistic.

Question has a verified solution.

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

The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…
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…

734 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