none
Renaming Attachments using Powershell and Exchange WebServices RRS feed

  • Question

  • I thought this would be simple but I haven't found the solution myself yet.  I'm just simply trying to run through each attachment in an email and rename them to my own specified format.  Currently I am just trying to rename the attachment to anything.  But, this errors out and does not work.  Does anyone have a solution for this?

    do{    
        $fiItems = $Inbox.FindItems($Sfha,$ivItemView)   
        #[Void]$service.LoadPropertiesForItems($fiItems,$psPropset)  
            foreach($Item in $fiItems.Items){        
                # Move the Message  
    			$hasAttachment = $false
    			$Item.Load()
    			foreach($attach in $Item.Attachments){
    				if($attach.Name.ToString().Contains(".pdf")){
    					$attach.Name = "test"
    					# attach.Name = "" AND attach.Name("") both do not work
    					$hasAttachment = $true
    				}
    			}
    			if($hasAttachment -eq $true){
    				$Item.Move($findFolderResults.Folders[0].Id)
    			}
            }    
            $ivItemView.Offset += $fiItems.Items.Count    
        }while($fiItems.MoreAvailable -eq $true)  
    
    

    Wednesday, September 23, 2015 2:36 PM

All replies

  • EWS doesn't support updating properties on Attachments (after submit, eg you can do it before a message is sent or created), you would have to remove the attachment and then re-add it to do it with EWS on a existing item. You can do with it with MAPI without the remove/add eg using something like Redemption http://www.dimastr.com/ would work in Powershell (make sure you match the bitness of powershell and outlook)

    Cheers
    Glen

    Thursday, September 24, 2015 5:28 AM