Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Can not Convert System._ComObject to Microsoft.Office.Interop.Outlook.MapiFolder

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 03-19-2007   #1 (permalink)
Mehfuz Hossain
Guest


 

Can not Convert System._ComObject to Microsoft.Office.Interop.Outlook.MapiFolder


Here is a litte power shell , that creates a rule for moving mail item
to a specifice folder.But whenever ,
i call

$oMove.Folder = $destFolder;

i get
Can not Convert System._ComObject to
Microsoft.Office.Interop.Outlook.MapiFolder


Full code.

$libraryPath = "C:\WINDOWS\assembly\GAC
\Microsoft.Office.Interop.Outlook\12.0.0.0__71e9bce111e9429c
\Microsoft.Office.Interop.Outlook.dll";
[void][System.Reflection.Assembly]::LoadFile($libraryPath);

[Microsoft.Office.Interop.Outlook.Application]$app = New-Object
Microsoft.Office.Interop.Outlook.ApplicationClass;
$namespace = $app.GetNamespace("MAPI");

$rules = $app.Session.DefaultStore.GetRules();

$defaultFolder =
$namespace.GetDefaultFolder([Microsoft.Office.Interop.Outlook.OlDefaultFolders]:lFolderInbox);

$rule = $rules.Create("Power shell rules",
[Microsoft.Office.Interop.Outlook.OlRuleType]:lRuleReceive);

$oFrom = $rule.Conditions.From;

$oRecip = $oFrom.Recipients.Add("someone@somedomain.com");

$oRecip.Resolve();
$oFrom.Enabled = $true;

$destFolder = $null;

$folders = $defaultFolder.Parent.Folders;
foreach($folder in $folders)
{
if ($folder.Name -eq "Work")
{
$destFolder = $folder;
}
}
$oMove = $rule.Actions.get_MoveToFolder();

$oMove.Folder = $destFolder;


#$oMove.Folder.FolderPath;

#$rules.Save();



--
Regards,
Mehfuz Hossain
http://www.mehfuz.com


My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Microsoft.VirtualServer.Interop.dll and the Microsoft.VMRCClientControl.Interop.dll ASun Virtual Server 0 08-12-2008 02:30 PM
Microsoft Announces New Version of Microsoft Dynamics CRM for 2007 Microsoft Office System and Windows Vista z3r010 Vista News 0 11-13-2006 09:11 PM
Microsoft Announces New Version of Microsoft Dynamics CRM for 2007 Microsoft Office System and Windows Vista z3r010 Vista News 0 11-07-2006 02:04 AM
Microsoft and Intel Help System Builders Get Ready for Windows Vista, the 2007 Microsoft Office System and Intel® Core™ 2 Duo Processors z3r010 Vista News 0 10-18-2006 03:07 AM
Microsoft and Intel Help System Builders Get Ready for Windows Vista, the 2007 Microsoft Office System and Intel® Core™ 2 Duo Processors z3r010 Vista News 0 10-12-2006 08:02 AM


Update your Vista Drivers Update Your Drivers Now!!

Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008