I installed the web service tools but when I run it remotely I just get a prompt not error. Anyone have any idea what i'm doing wrong. I have unread emails.
$MailboxName = "jj@acme.com"
#Load the dll
$WebServicesdll = "C:\Program Files\Microsoft\Exchange\Web Services\1.1\Microsoft.Exchange.WebServices.dll"
[void][Reflection.Assembly]::LoadFile($WebServicesdll)
$Service = New-object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2007_SP3)
#Connect to Exchange as the current user
$WindowsIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$SidBind = "LDAP://<SID=" + $WindowsIdentity.User.Value.ToString() + ">"
$AceUser = [ADSI]$SidBind
$Service.AutodiscoverUrl($AceUser.Mail.ToString())
#Hook up to the mailbox folder
$FolderId = New-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,$MailboxName)
$InboxFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($Service,$FolderId)
$SearchForUnRead = New-object Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo([Microsoft.Exchange.WebServices.Data.EmailMessageSchema]::IsRead, $false)
#Define my item and folder views
$ItemView = New-object Microsoft.Exchange.WebServices.Data.ItemView(2000)
$FolderView = New-object Microsoft.Exchange.WebServices.Data.FolderView(10000)
$FolderView.Traversal = [Microsoft.Exchange.WebServices.Data.FolderTraversal]::Deep
#Find all folders
$AllFolders = $InboxFolder.FindFolders($FolderView);
#Reset total count
$UnReadEmailTotal = 0
#Loop through all the folders found
ForEach ($Folder in $AllFolders){
"Currently working on : " + $Folder.DisplayName
If ($Folder.UnreadCount -gt 0){
"- Number of Unread Messages : " + $Folder.UnreadCount
$FindItemsResult = $Folder.FindItems($SearchForUnRead,$ItemView)
"-- Last Mail From : " + $FindItemsResult.Items[0].From.Name
"-- Subject : " + $FindItemsResult.Items[0].Subject
"-- Sent : " + $FindItemsResult.Items[0].DateTimeSent
}
$UnReadEmailTotal = $UnReadEmailTotal + $Folder.UnreadCount
}
#Output total unread items
"Total unread email : " + $UnReadEmailTotal