Save attachments

Hello, How save attachment? Code return error Method invocation failed because [System.String] doesn’t contain a method named ‘saveasfile’. My code is
$outlook = new-object -com outlook.application;

$namespace = $outlook.GetNameSpace(“MAPI”);

$emails = $namespace.Folders.Item(“Test”).Folders.Item(“Inbox”).Items | Select-Object -Property Categories,Subject,CreationTime,ReceivedTime,@{name=“Attachments”;expression={$.Attachments|%{$.DisplayName}}} | Sort-Object ReceivedTime -Descending

$saveFilePath = “C:\TEMP”

foreach ($email in $emails)


if (($email.attachments.count -ge 1) -and (($email.Subject -match “image”) -or ($email.Subject -match “plateb”)))


foreach ($attachment in $email.attachments)


$attachment.saveasfile((join-path $savefilepath $attachment))




Thank you

$attachment | Out-File (join-path $savefilepath $attachment)

Thank you very much.


I found an error, only the file name is saved to the file contents and the attachment itself is not saved. Can I help me?