I wanted to upload this script deletes only attachments from a user mailbox.

Good Morning 

This script was very helpful to me and im sure some admin on this forum will have a good use for it as well 

The below is what you will need 

This will only run on power shell 4.0 

you willl also need microsoft.exchange.webservices.dll 

below is the script enjoy, If anyone can help to show me the best way to have the output into a text file and then email it to someone else if not understandable 

#The module lives on the NY share drive
Import-Module -Name “\\homelabco.com\DFSShared\Infra\NY\Documentation\Powershell_Scripts\cleanup_Exchange_attachments\Microsoft\Exchange\Web Services\2.0\Microsoft.Exchange.WebServices.dll”
$exchangesession = New-PSSession –ConfigurationName Microsoft.Exchange –ConnectionUri ntex007.homelabco.com/.../ -Authentication Kerberos
Import-PSSession $exchangesession
function doFolder($inFolder) {
write-host “Folder:” $inFolder.displayName
$items = $inFolder.FindItems($itemFilter, $itemView)
foreach ($item in $items.Items) {
write-host $item.Subject
if ((New-TimeSpan (Get-Date) $item.DateTimeReceived).Days -lt 14) {
$item.Load()
foreach($attachment in $item.Attachments) {
write-host $attachment.Name
$item.Attachments.Remove($attachment)
}
$item.Update([Microsoft.Exchange.WebServices.Data.ConflictResolutionMode]::AutoResolve)
}
}
$folders = $service.FindFolders($inFolder.Id, $folderView)
foreach ($folder in $folders.Folders) {
doFolder($folder)
}
}

$userinput=Read-Host -Prompt "please enter your username"
$passwordinput=Read-Host "please enter your password"
$credentials = New-Object Microsoft.Exchange.WebServices.Data.WebCredentials($userinput,$passwordinput)
$service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010)
$service.Credentials = $credentials
$service.Url = "ntex007.homelabco.com/.../exchange.asmx"
$mailbox = Get-Mailbox $userinput
$folderView = New-Object Microsoft.Exchange.WebServices.Data.FolderView(1000)
$folderView.Traversal = [Microsoft.Exchange.WebServices.Data.FolderTraversal]::Shallow
$itemFilter = New-Object Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo([Microsoft.Exchange.WebServices.Data.EmailMessageSchema]::HasAttachments, $true)
$itemView = New-Object Microsoft.Exchange.WebServices.Data.ItemView(10000)
write-host $mailbox.displayName
# you can change the below to "deleteditems" "outbox" or "sentitems"
$folderId = New-Object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::SentItems, $mailbox.primarySmtpAddress.ToString())
$folder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service, $folderId)
doFolder($folder)