Move mails in outlook to subfolder

Hello im still looking for a simple solution of moving emails from one subfolder to another in outlook. I tried multiple ways but at the end nothing works. here is one example:

add-type -assemblyName "microsoft.office.interop.outlook"
add-type -assemblyname "System.runtime.interopservices"
$outlook = New-object -comobject outlook.application
$namespace = $outlook.getnamespace("MAPI")

$emails = $outlook.session.folders.item(1).folders.item("Folder1")

$targetfolder = $outlook.session.folders.item(1).folders.item"Folder2")
foreach($email in $emailtomove)
{
email.move($archivefolder)
}

The error message is:

mistake in opening methode, because [system._comobject] has no methode with “move”. vaguely translated from german.

so something is wrong with the last line.

can somebody pls help me out thank you in advance !

Hmmm … I don’t have any experiences with controlling Outlook by PowerShell. So I cannot recommend something meaningful for your actual issue. But shouldn’t be way easier to use Outlook rules to manage incomming mails and move them to different folders?

thank you olaf. the problem is im writing a little application and want a button do sort away the mails. i cant trigger rules with powershell unfortunately so i have to find a different way.

Why do you say this?

because i just cant find out how and the search for a solution drove me into insanity

The office COM objects are incredibly well documented, and as I mentioned in my previous post you can work out an awful lot with Get-Member.

You can trigger a rule like this:

$outlook = New-Object -ComObject Outlook.Application
$mapi = $outlook.GetNamespace('MAPI')
$folder = $mapi.Folders.Item('systemmails')
$inbox = $folder.FolderPath('Inbox')
$rules = $inbox.Store.GetRules()
$rules.Item('My Rule').Execute()
1 Like

thank you ! im sorry im very new, i dont even know what com objects are so please excuse me if my questions are annoying.

but this is exactly what i was looking for ! Thanks a lot !