Thursday, October 04, 2012

Reporting on the Item Age (Count and Size) in a Mailbox using EWS and Powershell (MEC Sample)

This is sample 2 from the Item Age section of my MEC talk in this sample we'll look at reporting on the Folder ItemCounts and Size of Item's in a Mailbox based on the age of those items.

To work out the Size and Item Count of all the Items in a Mailbox and be able to report on the age of those Items requires that you enumerate through every item in every folder in a Mailbox. Doing this on a mailbox with a large number of folder Items will take some time (it's pretty elementary Watson). So to reduce the amount of work that the server has to do to return information about all the Items in the Mailbox it's important to use the IdOnly BasePropertySet and then add the properties that are required. For this report the following properties are used.

Size, DateTimeReceived, DateTimeCreated

This script first uses a FindFolder operation to enumerate all folders in a Mailbox and then on each folder a findItems is used to enumerate ever item.

Using just these three properties and a Hashtable we can create an aggregation of Year part of the  DateTimeReceived (or DateTimeCreated) and the it produces a report like the following for all items in a Mailbox



I've also created a script that breaks out the age of items based on every folder and then create a report of every folder . This tends to be quite noisy but maybe useful if your looking for a more detailed breakdown.

I've put a download of the scripts here the code looks like

  1. ## Get the Mailbox to Access from the 1st commandline argument  
  2.   
  3. $MailboxName = $args[0]  
  4.   
  5. ## Load Managed API dll    
  6. Add-Type -Path "C:\Program Files\Microsoft\Exchange\Web Services\1.2\Microsoft.Exchange.WebServices.dll"    
  7.     
  8. ## Set Exchange Version    
  9. $ExchangeVersion = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP2    
  10.     
  11. ## Create Exchange Service Object    
  12. $service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService($ExchangeVersion)    
  13.     
  14. ## Set Credentials to use two options are availible Option1 to use explict credentials or Option 2 use the Default (logged On) credentials    
  15.     
  16. #Credentials Option 1 using UPN for the windows Account    
  17. $psCred = Get-Credential    
  18. $creds = New-Object System.Net.NetworkCredential($psCred.UserName.ToString(),$psCred.GetNetworkCredential().password.ToString())    
  19. $service.Credentials = $creds        
  20.     
  21. #Credentials Option 2    
  22. #service.UseDefaultCredentials = $true    
  23.     
  24. ## Choose to ignore any SSL Warning issues caused by Self Signed Certificates    
  25.     
  26. ## Code From http://poshcode.org/624  
  27. ## Create a compilation environment  
  28. $Provider=New-Object Microsoft.CSharp.CSharpCodeProvider  
  29. $Compiler=$Provider.CreateCompiler()  
  30. $Params=New-Object System.CodeDom.Compiler.CompilerParameters  
  31. $Params.GenerateExecutable=$False  
  32. $Params.GenerateInMemory=$True  
  33. $Params.IncludeDebugInformation=$False  
  34. $Params.ReferencedAssemblies.Add("System.DLL") | Out-Null  
  35.   
  36. $TASource=@' 
  37.   namespace Local.ToolkitExtensions.Net.CertificatePolicy{ 
  38.     public class TrustAll : System.Net.ICertificatePolicy { 
  39.       public TrustAll() {  
  40.       } 
  41.       public bool CheckValidationResult(System.Net.ServicePoint sp, 
  42.         System.Security.Cryptography.X509Certificates.X509Certificate cert,  
  43.         System.Net.WebRequest req, int problem) { 
  44.         return true; 
  45.       } 
  46.     } 
  47.   } 
  48. '@   
  49. $TAResults=$Provider.CompileAssemblyFromSource($Params,$TASource)  
  50. $TAAssembly=$TAResults.CompiledAssembly  
  51.   
  52. ## We now create an instance of the TrustAll and attach it to the ServicePointManager  
  53. $TrustAll=$TAAssembly.CreateInstance("Local.ToolkitExtensions.Net.CertificatePolicy.TrustAll")  
  54. [System.Net.ServicePointManager]::CertificatePolicy=$TrustAll  
  55.   
  56. ## end code from http://poshcode.org/624  
  57.     
  58. ## Set the URL of the CAS (Client Access Server) to use two options are availbe to use Autodiscover to find the CAS URL or Hardcode the CAS to use    
  59.     
  60. #CAS URL Option 1 Autodiscover    
  61. $service.AutodiscoverUrl($MailboxName,{$true})    
  62. "Using CAS Server : " + $Service.url     
  63.      
  64. #CAS URL Option 2 Hardcoded    
  65.     
  66. #$uri=[system.URI] "https://casservername/ews/exchange.asmx"    
  67. #$service.Url = $uri      
  68.     
  69. ## Optional section for Exchange Impersonation    
  70.     
  71. #$service.ImpersonatedUserId = new-object Microsoft.Exchange.WebServices.Data.ImpersonatedUserId([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress, $MailboxName)   
  72.   
  73. # Bind to the Inbox Folder  
  74. $folderid= new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,$MailboxName)     
  75. $Inbox = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderid)  
  76.   
  77. #Define ItemView to retrive just 1000 Items      
  78. $ivItemView =  New-Object Microsoft.Exchange.WebServices.Data.ItemView(1000)    
  79. $psPropset= new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::IdOnly)    
  80. $psPropset.Add([Microsoft.Exchange.WebServices.Data.ItemSchema]::Size)  
  81. $psPropset.Add([Microsoft.Exchange.WebServices.Data.ItemSchema]::DateTimeReceived)  
  82. $psPropset.Add([Microsoft.Exchange.WebServices.Data.ItemSchema]::DateTimeCreated)  
  83. $ivItemView.PropertySet = $psPropset  
  84. $TotalSize = 0  
  85. $TotalItemCount = 0  
  86.   
  87.   
  88. #Define Function to convert String to FolderPath    
  89. function ConvertToString($ipInputString){    
  90.     $Val1Text = ""    
  91.     for ($clInt=0;$clInt -lt $ipInputString.length;$clInt++){    
  92.             $Val1Text = $Val1Text + [Convert]::ToString([Convert]::ToChar([Convert]::ToInt32($ipInputString.Substring($clInt,2),16)))    
  93.             $clInt++    
  94.     }    
  95.     return $Val1Text    
  96. }   
  97.   
  98. #Define Extended properties    
  99. $PR_FOLDER_TYPE = new-object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(13825,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Integer);    
  100. $folderidcnt = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::MsgFolderRoot,$MailboxName)    
  101. #Define the FolderView used for Export should not be any larger then 1000 folders due to throttling    
  102. $fvFolderView =  New-Object Microsoft.Exchange.WebServices.Data.FolderView(1000)    
  103. #Deep Transval will ensure all folders in the search path are returned    
  104. $fvFolderView.Traversal = [Microsoft.Exchange.WebServices.Data.FolderTraversal]::Deep;    
  105. $psPropertySet = new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)    
  106. $PR_Folder_Path = new-object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(26293, [Microsoft.Exchange.WebServices.Data.MapiPropertyType]::String);    
  107. #Add Properties to the  Property Set    
  108. $psPropertySet.Add($PR_Folder_Path);    
  109. $fvFolderView.PropertySet = $psPropertySet;    
  110. #The Search filter will exclude any Search Folders    
  111. $sfSearchFilter = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo($PR_FOLDER_TYPE,"1")    
  112. $fiResult = $null    
  113. $rptHash = @{}        
  114. $minYear = (Get-Date).Year  
  115. $maxYear = (Get-Date).Year  
  116. #The Do loop will handle any paging that is required if there are more the 1000 folders in a mailbox    
  117. do {    
  118.     $fiResult = $Service.FindFolders($folderidcnt,$sfSearchFilter,$fvFolderView)    
  119.     foreach($ffFolder in $fiResult.Folders){    
  120.         $foldpathval = $null    
  121.         #Try to get the FolderPath Value and then covert it to a usable String     
  122.         if ($ffFolder.TryGetProperty($PR_Folder_Path,[ref] $foldpathval))    
  123.         {    
  124.             $binarry = [Text.Encoding]::UTF8.GetBytes($foldpathval)    
  125.             $hexArr = $binarry | ForEach-Object { $_.ToString("X2") }    
  126.             $hexString = $hexArr -join ''    
  127.             $hexString = $hexString.Replace("FEFF""5C00")    
  128.             $fpath = ConvertToString($hexString)    
  129.         }    
  130.         "FolderPath : " + $fpath    
  131.           
  132.         #Define ItemView to retrive just 1000 Items      
  133.         $ivItemView =  New-Object Microsoft.Exchange.WebServices.Data.ItemView(1000)    
  134.         $psPropset= new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::IdOnly)    
  135.         $psPropset.Add([Microsoft.Exchange.WebServices.Data.ItemSchema]::Size)  
  136.         $psPropset.Add([Microsoft.Exchange.WebServices.Data.ItemSchema]::DateTimeReceived)  
  137.         $psPropset.Add([Microsoft.Exchange.WebServices.Data.ItemSchema]::DateTimeCreated)  
  138.         $ivItemView.PropertySet = $psPropset  
  139.           
  140.           
  141.         $fiItems = $null      
  142.         do{      
  143.             $fiItems = $service.FindItems($ffFolder.Id,$ivItemView)      
  144.             #[Void]$service.LoadPropertiesForItems($fiItems,$psPropset)    
  145.             foreach($Item in $fiItems.Items){  
  146.                 $dateVal = $null  
  147.                 if($Item.TryGetProperty([Microsoft.Exchange.WebServices.Data.ItemSchema]::DateTimeReceived,[ref]$dateVal )-eq $false){  
  148.                     $dateVal = $Item.DateTimeCreated  
  149.                 }  
  150.                 if($rptHash.ContainsKey($dateVal.Year)){  
  151.                     $rptHash[$dateVal.Year].TotalNumber += 1  
  152.                     $rptHash[$dateVal.Year].TotalSize += [Int64]$Item.Size  
  153.                 }  
  154.                 else{  
  155.                     $rptObj = "" | Select TotalNumber,TotalSize  
  156.                     $rptObj.TotalNumber = 1  
  157.                     $rptObj.TotalSize = [Int64]$Item.Size  
  158.                     $rptHash.add($dateVal.Year,$rptObj)  
  159.                     if($dateVal.Year -lt $minYear){$minYear = $dateVal.Year}  
  160.                 }  
  161.             }      
  162.             $ivItemView.Offset += $fiItems.Items.Count      
  163.         }while($fiItems.MoreAvailable -eq $true)          
  164.     }   
  165.     $fvFolderView.Offset += $fiResult.Folders.Count  
  166. }while($fiResult.MoreAvailable -eq $true)  
  167. $rptCollection = @()  
  168. $fnFinalreporttlt = "" | Select Name,TotalNumber,TotalSize  
  169. $fnFinalreporttlt.Name = $MailboxName  
  170. $rptCollection += $fnFinalreporttlt  
  171. $fnFinalreport = "" | Select Name,TotalNumber,TotalSize  
  172. $rptCollection += $fnFinalreport  
  173. $rptHash.GetEnumerator() | Sort-Object Name | ForEach-Object {  
  174.     $fnFinalreport = "" | Select Name,TotalNumber,TotalSize  
  175.     $fnFinalreport.Name = $_.key  
  176.     $fnFinalreport.TotalNumber = $rptHash[$_.key].TotalNumber  
  177.     $fnFinalreport.TotalSize = [Math]::Round($rptHash[$_.key].TotalSize/1MB,2)  
  178.     $fnFinalreporttlt.TotalNumber += $rptHash[$_.key].TotalNumber  
  179.     $fnFinalreporttlt.TotalSize += [Math]::Round($rptHash[$_.key].TotalSize/1MB,2)  
  180.     $rptCollection += $fnFinalreport  
  181. }  
  182.   
  183. $tableStyle = @" 
  184. <style> 
  185. BODY{background-color:white;} 
  186. TABLE{border-width: 1px; 
  187.   border-style: solid; 
  188.   border-color: black; 
  189.   border-collapse: collapse; 
  190. } 
  191. TH{border-width: 1px; 
  192.   padding: 10px; 
  193.   border-style: solid; 
  194.   border-color: black; 
  195.   background-color:#66CCCC 
  196. } 
  197. TD{border-width: 1px; 
  198.   padding: 2px; 
  199.   border-style: solid; 
  200.   border-color: black; 
  201.   background-color:white 
  202. } 
  203. </style> 
  204. "@  
  205.     
  206. $body = @" 
  207. <p style="font-size:25px;family:calibri;color:#ff9100">  
  208. $TableHeader  
  209. </p>  
  210. "@  
  211.   
  212. $rptCollection | ConvertTo-HTML -head $tableStyle –body $body | Out-File c:\temp\MailboxAgeReportSummary.htm  


36 comments:

Anonymous said...

I am trying to get this to work for Exchange 2007 - do you have a version that pulls this data for Exchange 2007 SP3?

Glen Scales said...

It should work okay on 2007 just change the line

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

to

$ExchangeVersion = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2007_SP1
Cheers
Glen

Anonymous said...

I am using the above script to copy folder structure. the problem is with a folder in different language (Hebrew) it is not recognizing. The part which is causing problem is $binarry = [Text.Encoding]::UTF8.GetBytes($foldpathval). It converts Hebrew characters to garbage value

Glen Scales said...

I've never had to work with Hebrew it should be the same a any other nonlatin character sets ? eg Greek, Russian etc. The only slight bug I've noticed with PR_Folder_Path is that it can vary depending how you retrieve it which indicates its a computed property. Are you getting the value from FindItems or a direct Bind? I would always try to use FindItems as I know I think I've had the same issue with Bind.

Cheers
Glen

Anonymous said...

in which situtaion would we require to convert to utf8 and again decode? In my case the $foldpathval works for all languages without converting it to utf8.

Anonymous said...

anyone get this to work on exchange 2007?

Anonymous said...

This path in the code does not exist on exchange 2007:

"C:\Program Files\Microsoft\Exchange\Web Services\1.2\Microsoft.Exchange.WebServices.dll"

Glen Scales said...

You need to install the EWS Managed API the latest is 2.0 so you'll need to change the path to reflect this as well as changing the version as mentioned in another comment

Cheers
Glen

Simon Edwards said...

Glen, thanks for this, works well.

Is there a way I can run this against all mailboxes without the need to enter a username/password?

I'm trying to report on all mail in the database older than X and report size ....

Glen Scales said...

I you rewrite it as a function and then call the function for each mailbox see something like http://gsexdev.blogspot.com.au/2013/09/junk-email-scl-report-using-ews-and.html for an example

Anonymous said...

Hi.
Great post.
script is failing with below error:
exception calling bind with 2 arguments: the request failed. The remote server returned error: 401 unauthorized.

can you please help me

Anonymous said...

Is there a way to leverage this script to also include the total mailbox size for the date range? Ultimately the objective is to create an Ex2K10 Org wide mailbox database size report for all databases based on date range. Thank you. MM

Glen Scales said...

The TotalSize would give you the Mailbox Size for the data range. This is basically worked out but adding all the Sizes together for the Items within the data range

Anonymous said...

This is great, but it doesn't traverse into Exchange Personal Archives. Any suggestions on how to get this same report for Personal Archive folders?

Glen Scales said...

Change

msgfolderoot

to

ArchiveMsgFolderRoot

or maybe have a look at http://gallery.technet.microsoft.com/office/Exchange-Server-Mailbox-7dd53529 which does a lot more

Cheers
Glen

Dimmie said...

It is not working on Exch2010 SP3, giving following error:

Exception calling "Bind" with "2" argument(s): "Exchange Server doesn't support the requested version."
At C:\MailboxItemAgeSI\MailboxItemAgeSummary.ps1:75 char:60
+ $Inbox = [Microsoft.Exchange.WebServices.Data.Folder]::Bind <<<< ($service,$folderid)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException

Glen Scales said...

That error is saying you have tried to use a unsupported server version eg make sure you have

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

Don't try to use SP3 in the version as there is no Schema update on SP3 so this wont work

Dimmie said...

Thanks Glen but how do I get data from multiple mailboxes?
$MailboxName = $args[0] (Sorry, I don't understand this much). I replaced $args[0] with single user email address and it's working perfect but need to know to get the info from multiple users.

Glen Scales said...

You need to rewrite the script to use a CSV instead eg you need a csv like

glen@domain.onmicrosoft.com
dlister@domain.onmicrosoft.com

and rewrite the script like

https://www.dropbox.com/s/yutnb2xc6gnxjw9/MailboxItemAgeSummaryCSV.zip?dl=0

cheers
Glen

Anonymous said...

Is there an example of how to run this script. What is the format of the date etc?

Glen Scales said...

This script only accepts one parameter which is the name of the Mailbox, not sure what you mean by the format of the Date

Glen

Anonymous said...

ok, so lets say i want to search for emails before july 1 2014..

Glen Scales said...

Modify the Item enumeration with an If statement to exclude anything older then that date eg

foreach($Item in $fiItems.Items){
$dateVal = $null
if($Item.TryGetProperty([Microsoft.Exchange.WebServices.Data.ItemSchema]::DateTimeReceived,[ref]$dateVal )-eq $false){
$dateVal = $Item.DateTimeCreated
}
if($dateVal -lt (Get-Date -Year 2014 -Month 07-day 1)){
if($rptHash.ContainsKey($dateVal.Year)){
$rptHash[$dateVal.Year].TotalNumber += 1
$rptHash[$dateVal.Year].TotalSize += [Int64]$Item.Size
}
else{
$rptObj = "" | Select TotalNumber,TotalSize
$rptObj.TotalNumber = 1
$rptObj.TotalSize = [Int64]$Item.Size
$rptHash.add($dateVal.Year,$rptObj)
if($dateVal.Year -lt $minYear){$minYear = $dateVal.Year}
}
}
}

Cheers
Glen

Anonymous said...

Thanks! Will give this a shot!

Jim said...

How would I augment this to iterate through all mailboxes in a datastore? I'm planning a migration and I'd like to have a report for all users.

Diane Burns said...

Hi Glen,
I just want to congratulate you on a great script!
I have managed to get it to run against a shared mailbox, but I'm having trouble with the MailboxAgeDetailed script and it's throwing the following errors:

Exception calling "FindFolders" with "3" argument(s): "The Url property on ExchangeService object must be set."
At line:2 char:37
+ $fiResult = $Service.FindFolders <<<< ($folderidcnt,$sfSearchFilter,$fvFolderView)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException

You cannot call a method on a null-valued expression.
At line:6 char:37
+ if ($ffFolder.TryGetProperty <<<< ($PR_Folder_Path,[ref] $foldpathval))
+ CategoryInfo : InvalidOperation: (TryGetProperty:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

FolderPath : \Tasks
Exception calling "FindItems" with "2" argument(s): "The element at position 0 is invalid
Parameter name: parentFolderIds"
At line:25 char:42
+ $fiItems = $service.FindItems <<<< ($ffFolder.Id,$ivItemView)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException

You cannot call a method on a null-valued expression.
At line:29 char:40
+ if($Item.TryGetProperty <<<< ([Microsoft.Exchange.WebServices.Data.ItemSchema]::DateTimeReceived,[ref
]$dateVal )-eq $false){
+ CategoryInfo : InvalidOperation: (TryGetProperty:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

Exception calling "ContainsKey" with "1" argument(s): "Key cannot be null.
Parameter name: key"
At line:32 char:40
+ if($rptHash.ContainsKey <<<< ($dateVal.Year)){
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException

Just to be clear, I have edited the Detailed script in exactly the same way that I edited the Summary script. Also you may need to know that our Microsoft.Exchange.WebServices.dll file is in C:\Program Files\Exclaimer Ltd\Signature Manager Exchange Edition so I have had to edit the Add-Type -Path accordingly, but as I said this worked for the Summary script.

Any help would be greatly appreciated.

Many thanks

Diane said...

Hi Glen,

Scrap the above - I fixed it in the end (missed copying something across!), but I just thought I would point out the following typo:

#Credentials Option 2
service.UseDefaultCredentials = $true

should read:

#Credentials Option 2
$service.UseDefaultCredentials = $true

Many thanks

Diane said...

Hi Glen,

Would you be able to help me with this one please? I need a similar report on a shared mailbox which shows the number of mailbox items that are a certain age, for example 4 hours old, 1 day, 2 days, etc
Which section would I need to edit and how?

Many thanks

Anonymous said...

Hello Glen,

Do you have something that could work with exchange 2010 SP3?

Thanks
Geoff

Glen Scales said...

This will work fine on 2010 sp3

Robert Martindale said...

Hello Glen. I have read through this entire thread and am using the option listed above where I supply a csv file to run through a large number of smtp email addresses. However, I need to ONLY pull the information from the "Deleted Items" folder. How do I modify your script so it only does ONE folder?

By the way, your script has saved my bacon. I have been searching for a way to obtain how many (and total size) items are in the deleted items folder that are older than 14 days.

Much appreciate your help.

Thanks,
Rob.

Glen Scales said...

Try the script on https://github.com/gscales/Powershell-Scripts/blob/master/GetItemAgeFromItemsInFolder.ps1 and run it like

get-FolderItemsAge -MailboxName user@mailbox.com -FolderPath '\Deleted Items'

Anonymous said...

Will this script run on Exchange 2013 SP1?

Willy Ceppi said...

Hello Glenn, I hope this thread is still alive. :)

I am unable to run the script.
Neither of the 4 (these 2 and the "sample 1")

First of all, in an Exchange 2007 SP3 running on Windows Server 2003 R2, the "Add-Type" commandlet is not recognized.
So I moved to a W 2008 R2 and it solved that part.

Still, when I try to run it, I get the following
(first I hardcoded the CAS server to avoid any autodiscover issues, I changed the credential option to Use Default, changed the Exchange Version for 2007_SP3 and changed the WebServices path to \2.0\)

Exception calling "Bind" with "2" argument(s): "The request failed. The remote server returned an error: (502) Bad Gateway."
At D:\Temp2\MailboxItemAgeSummary1.ps1:75 char:60
+ $Inbox = [Microsoft.Exchange.WebServices.Data.Folder]::Bind <<<< ($service,$folderid)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException

Exception calling "FindFolders" with "3" argument(s): "The request failed. The remote server returned an error: (502) Bad Gateway."
At D:\Temp2\MailboxItemAgeSummary1.ps1:118 char:37
+ $fiResult = $Service.FindFolders <<<< ($folderidcnt,$sfSearchFilter,$fvFolderView)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException

You cannot call a method on a null-valued expression.
At D:\Temp2\MailboxItemAgeSummary1.ps1:122 char:37
+ if ($ffFolder.TryGetProperty <<<< ($PR_Folder_Path,[ref] $foldpathval))
+ CategoryInfo : InvalidOperation: (TryGetProperty:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull


The CAS server I am running this in, is in a different site from the CAS/Mailbox I am querying.
Could that be the problem?
Should I run it in the same site?
if that is the case, how can I run it in a Win2003R2 that doesn't like "Add-Type"?

Thank you

Anonymous said...
This comment has been removed by a blog administrator.
Geoffrey Ouvrard said...

Hello Glen,
I think your script is great, I work it to find the size of all mails send before 01/01/2015 on all mailboxes.
When I run the script I get this error :
New-Object : Impossible de convertir l'argument « 1 » (valeur « Administrateur.Principal@prb.fr ») de « FolderId » en t
ype « Microsoft.Exchange.WebServices.Data.Mailbox » : « Impossible de convertir la valeur « Administrateur.Principal@pr
b.fr » du type « Microsoft.Exchange.Data.SmtpAddress » en type « Microsoft.Exchange.WebServices.Data.Mailbox ». »
Au niveau de ligne : 8 Caractère : 26
+ $folderid= new-object <<<< Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.Wel
lKnownFolderName]::Outbox,$MailboxName)
+ CategoryInfo : InvalidOperation: (:) [New-Object], MethodException
+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

I am a beginner on powershell and exchange powershell, so if you can help me, it would be great !

Thank !
Geoffrey