?
Solved

Create Outlook "Rules And Alerts" with Powershell

Posted on 2010-11-10
7
Medium Priority
?
2,657 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
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
Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

 

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

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

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

Measuring Server's processing rate with a simple powershell command. The differences in processing rate also was recorded in different use-cases, when a server in free and busy states.
There can be many situations demanding the conversion of Outlook OST files to PST format and as such, there is no shortage of automated tools to perform this conversion. However, what makes Stellar OST to PST converter stand above the rest? Let us e…
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 …
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

862 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