Hi, I could use this script to get the emails in my mailbox, But do I get the messages in any mailbox. How can i specify the alias or smtp address of the mailbox to get the emails within the mailbox
#Load the API DLL
$dllpath = "C:\Program Files\Microsoft\Exchange\Web Services\1.1\Microsoft.Exchange.WebServices.dll"
[void][Reflection.Assembly]::LoadFile($dllpath)
#Create a new service object
$service = new-object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2007_SP1)
# Fancy Way to Check the user and dynamically assign the Autodiscover URL
$windowsIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$sidbind = "LDAP://"
$aceuser = [ADSI]$sidbind
$service.AutodiscoverUrl($aceuser.mail.ToString())
#Do some stuff
$inbox = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service, [Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox)
$viewCount = 60
$view = New-Object Microsoft.Exchange.WebServices.Data.ItemView($viewCount)
$findResults = $service.FindItems([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,$view)
$i = 0
#$cpsFound = 0
while ($i -le ($viewCount - 1))
{
$currdate = Get-Date
#$findResults.Items[$i].Id |fl *
if($findResults.Items[$i].DateTimeSent.ToShortDateString() -eq $currdate.ToShortDateString())
{
if($findResults.Items[$i].Subject.Contains("STRING_UR_LOOKING_4") -eq $True)
{
"Subject : " + $findResults.Items[$i].Subject
$EmailItemID = $findResults.Items[$i].Id
$currEmailItem = [Microsoft.Exchange.WebServices.Data.Item]::Bind($service,$EmailItemID)
$currSubject = $findResults.Items[$i].Subject
$myParseCmd = $currSubject.Split("|")
#$currEmailItem.Sender.Address
}
}
# Increment the while loop
$i +=1
}
This script was taken from Export Email Header Information via PowerShell