I am trying to copy some items from "Inbox" to "Sent Items\TEMP" in Outlook. So far I was able to pick up desired messages, based on the subject line, but then I try to copy them with no success. Where am I going wrong? Thanks! Please note, when i do a write-host to retrieve the item I'm looking for, it comes up with no issues, so I am able to retrieve the email with subject line of "Test", but not copy it.
Error message:
Cannot find an overload for "Copy" and the argument count: "1"
Code:
$outlook = New-Object -comobject outlook.application;
$mapi = $outlook.GetNamespace('MAPI').GetDefaultFolder(6);
$mapi2 = $outlook.GetNamespace('MAPI').GetDefaultFolder(5);
$subFolders2 = $mapi.Folders | ? {$_.FolderPath.EndsWith('TEMP')};
$mapi.Items | ForEach-Object {If ($_.Subject -Like '*TEst*'){$_.Copy($subFolders2)}$_.Save()}
MailItem.Copy does not take any parameters. It returns an instance of the MailItem object; you can then call MailItem.Move and pass the pointer to the destination folder.