Udostępnij za pośrednictwem


Using Exchange EWS To Obtain Voicemail Statistics


Exchange PFE Daya Patil demonstrates how versatile the Exchange Web Services API is by providing granular reporting detail on Exchange voicemail messages


One of our customers needed a way to determine the number of Voicemails and their size in each folder from their Exchange 2010 organization.

We quickly wrote a script to get this information, and wanted to share with the community to help those with similar requirements.   

 

In the script, we determine the number of voicemail from a given user’s mailbox. Script parameters can be changed according to your requirements. 

Here is the script to count the number of voicemail item and their size for a specific mailbox using EWS. The script can be modified to get the CSV output for complete environment.

The script uses Exchange Web services managed API 2.0  with PowerShell, which you need to first download from the Microsoft download centre.

 

As always, treat this as sample code and you must fully test it in a non-production environment. 

 

<# DISCLAIMER STARTS

This Sample Code is provided for the purpose of illustration only and is not intended to be used in a #production environment. THIS SAMPLE CODE AND ANY RELATED INFORMATION ARE PROVIDED "AS IS" #WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO #THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. We #grant You a nonexclusive, royalty-free right to use and modify the Sample Code and to reproduce and #distribute the object code form of the Sample Code, provided that You agree:(i) to not use Our name, #logo, or trademarks to market Your software product in which the Sample Code is embedded; (ii) to #include a valid copyright notice on Your software product in which the Sample Code is embedded; and #(iii) to indemnify, hold harmless, and defend Us and Our suppliers from and against any claims or #lawsuits, including attorneys’ fees, that arise or result from the use or distribution of the Sample Code."

"This sample script is not supported under any Microsoft standard support program or service. The #sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied #warranties including, without limitation, any implied warranties of merchantability or of fitness for a #particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in #the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, #without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or #documentation, even if Microsoft has been advised of the possibility of such damages"

DISCLAIMER ENDS # >

*********************

## Load Managed API dll

Import-module "C:\Program Files (x86)\Microsoft\Exchange\Web Services\2.1\Microsoft.Exchange.WebServices.dll" 

                $ErrorActionPreference = "silentlycontinue"

## Set Exchange Version 

                $ExchangeVersion = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP1 

                <#$sid = [System.Security.Principal.WindowsIdentity]::GetCurrent().User.Value

                $user = [ADSI]"LDAP://<SID=$sid>"

                #$service.AutodiscoverUrl($user.Properties.mail) #>

    $service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService($ExchangeVersion) 

    $uri=[system.URI] "https://exch2010-1.contoso.com/ews/exchange.asmx

               $service.Url = $uri

## Specify the mailbox for which voicemail count is needed

    $mailboxname = "fsadministrator@contoso.com"

# Connecting to Folder root of above mailbox. The list of all folders to which you can connect using EWS is available here.

$rfRootFolderID = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::MsgFolderRoot,$MailboxName)

$rfRootFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$rfRootFolderID)

# Setting scope for EWS to process items

              $fvFolderView = New-Object Microsoft.Exchange.WebServices.Data.FolderView(10000);

               $fvFolderView.Traversal = [Microsoft.Exchange.WebServices.Data.FolderTraversal]::Deep

$ffResponse = $rfRootFolder.FindFolders($fvFolderView)

$ffresponce.displayname

# Setup Basic EWS Properties for Item Search – of type “IPM.Note.Microsoft.Voicemail.UM.CA“

$searchFilterForwardRule         = New-Object Microsoft.Exchange.WebServices.Data.SearchFilter+ContainsSubstring([Microsoft.Exchange.WebServices.Data.ItemSchema]::ItemClass, "IPM.Note.Microsoft.Voicemail.UM.CA", [Microsoft.Exchange.WebServices.Data.ContainmentMode]::Prefixed, [Microsoft.Exchange.WebServices.Data.ComparisonMode]::Exact)

$itemViewForwardRule             = New-Object Microsoft.Exchange.WebServices.Data.ItemView(30, 0, [Microsoft.Exchange.Webservices.Data.OffsetBasePoint]::Beginning)

clear

$finalreport= @()

# Loop to go through each folder

foreach ($folder in $ffResponse.Folders)

{

$findResults = $folder.FindItems($searchFilterForwardRule, $itemViewForwardRule)

$Name = $folder.displayname

$count= ($findresults.items).count

$size = ($findresults |select size|measure-object -property size -sum).sum/1MB

$result = New-Object psobject -Property  @{

                                                   Foldername = $Name

                                                  Count = $count

                                                Size = $Size

                                              }

                              $finalreport += $result   

}

$finalreport |ft –AutoSize

# Taking output to CSV file

$finalreport |Select Foldername,Count,Size |Export-Csv –Path C:\Output.csv –NoTypeInformation

 

 


Published by MSPFE editor Rhoderick Milne