Reputation: 69
With PowerShell, I'm trying to write a script that will move an email from my inbox to a folder, once I have finished doing what I want with it. This is what I have so far.
$folder = $namespace.GetDefaultFolder(6)
$filepath = "C:\Users\Documents\PowerShell"
$folder.Items| foreach {
$_.attachments|foreach {
$filename = $_.filename
If ($filename.Contains("test.xls")) {
$_.saveasfile((Join-Path $filepath $filename))
Rename-Item -LiteralPath '.\test.xls' -NewName "Server.xls"
#File move code should go here
}
If ($filename.Contains("test2.xls")) {
$_.saveasfile((Join-Path $filepath $filename))
Rename-Item -LiteralPath '.\test2.xls' -NewName "Workstation.xls"
#File move code should go here
}
}
}
Right now I have it set up so that it will search my inbox for any email containing .xls attatchments with a certain name, rename the .xls attachment, and save it to a specified folder in my documents. Now, once I'm done with that, I want to move the original email containing the attachment to a folder within my Outlook email called "test folder". I've seen a few examples online of people doing something similar to this, but nothing seems to be working for me. Any advice on how to do this?
Upvotes: 2
Views: 11163
Reputation: 49397
You need to use the Move method which moves a Microsoft Outlook item to a new folder.
To find the required folder you can iterate trough them using the Folder.Folders
property. See How to: Enumerate Folders for more information.
Upvotes: 2