jamorlando
asked on
Create Outlook "Rules And Alerts" with Powershell
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#{00063 006-0000-0 000-c000-0 0000000004 6}" to type "Microsoft.Office.Interop. Outlook.MA PIFolder". "
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
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#{00063
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
ASKER
Dave, but if after that you were to run:
$inbox.Folders.item("bob") | fl
It returns data ... presumably the folder data.
$inbox.Folders.item("bob")
It returns data ... presumably the folder data.
you are correct. Odd. It should just work...
ASKER
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.
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.
ASKER
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.getDefaultFolde r($olFolde rs::olFold erInbox)
According to MSDN, this records type Microsoft.Office.Interop.O utlook.MAP IFolder
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,
If you run:
$namespace.GetType
You can see the type is NameSpaceClass
In the code, there is the line:
$inbox = $namespace.getDefaultFolde
According to MSDN, this records type Microsoft.Office.Interop.O
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,
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Other thread solved my problem.
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".