none
Getting error on EWS FindItems method 'Specified argument was out of the range of valid values.' parameter name length RRS feed

  • Question

  • Hi there

    I am working on an EWS script using impersonation to enumerate a users folders and report on retention tags - I have this working but the customer has since come back and requested retention tag report at the email level per each folder - my code is like the following:

         $view = New-Object Microsoft.Exchange.WebServices.Data.ItemView -ArgumentList 5
                            $propertyset = New-Object Microsoft.Exchange.WebServices.Data.PropertySet(
                                
                                [Microsoft.Exchange.WebServices.Data.BasePropertySet]::IdOnly,
                                [Microsoft.Exchange.WebServices.Data.ItemSchema]::Subject,
                                [Microsoft.Exchange.WebServices.Data.ItemSchema]::PolicyTag,
                                [Microsoft.Exchange.WebServices.Data.ItemSchema]::ArchiveTag

                            )
                            $view.PropertySet = $propertyset


                            foreach($oFindFolder in $oFindFolders1){

                                

                                            $currentfolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($exchangeService,$oFindFolder.Id)
                                            $items = $exchangeService.FindItems($currentfolder.ParentFolderId,$view)

                                            $items | ForEach-Object{
                                                New-Object PSObject -Property @{
                                                    FolderName = $oFindFolder.DisplayName
                                                    Id = $_.Id.ToString()
                                                    Subject = $_.Subject
                                                    PolicyTag = $_.PolicyTag
                                                    ArchiveTag = $_.ArchiveTag
                                                }


                                    }
                                                   
                            }

    However at that point the script sort of hangs - I don't get the prompt back but have any errors generated to a log file and am getting :  Specified argument was out of the range of valid values.' parameter name length. I thought you needed to bind to a specific folder before you could call the FindItems method on it? I tried FindItems without Binding and it also errors? Can someone guide me please on this?

    Thursday, July 13, 2017 10:31 PM

Answers

  • >>so I am not sure of an instance where you need to bind to a folder

    You don't the underlying FindItem EWS operation only requires the EWSId of the folder your trying to enumerate items from, in the Managed API there are two FindItems method one of the ExchangeService class and one of the folder class. They both do exactly the same thing as to when and where you use them is really up you as it may improve the readability of some code to use the Folder Method over the Service Method but they are technically the same thing.  

    With grouping I would suggest you first read https://msdn.microsoft.com/en-us/library/office/dn592092(v=exchg.150).aspx then ask specific questions around that (sounds like overkill for what your trying to do however).


    • Edited by Glen ScalesMVP Monday, July 17, 2017 2:47 AM typo
    • Marked as answer by nickkinn Tuesday, July 18, 2017 8:44 AM
    Monday, July 17, 2017 2:47 AM

All replies

  • Well it started to work soon as I did this:

    $items = $exchangeService.FindItems($oFindFolder.Id,$view)

    also there appears to be no need to have to bind to the folder - so I am not sure of an instance where you need to bind to a folder - the only other thing im curious about is I can see there is a method overload for FindItems that takes (FolderId, view , Grouping)  since i will be reporting back a lot of information this looks like a good option - but unsure how to use it or what the output looks like

    Friday, July 14, 2017 3:54 PM
  • >>so I am not sure of an instance where you need to bind to a folder

    You don't the underlying FindItem EWS operation only requires the EWSId of the folder your trying to enumerate items from, in the Managed API there are two FindItems method one of the ExchangeService class and one of the folder class. They both do exactly the same thing as to when and where you use them is really up you as it may improve the readability of some code to use the Folder Method over the Service Method but they are technically the same thing.  

    With grouping I would suggest you first read https://msdn.microsoft.com/en-us/library/office/dn592092(v=exchg.150).aspx then ask specific questions around that (sounds like overkill for what your trying to do however).


    • Edited by Glen ScalesMVP Monday, July 17, 2017 2:47 AM typo
    • Marked as answer by nickkinn Tuesday, July 18, 2017 8:44 AM
    Monday, July 17, 2017 2:47 AM