Unable to Find Type FindItemsResults in Exchange Web Services 2.0 RRS feed

  • Question

  • Hi,

    I have an Exchange 2010 server and I'm writing a small script to query a mailbox using Exchange web services 2.0.

    I've loaded the DLL and can connect to my mailbox to get the correct message count, but I'm running into an issue with trying to cast a variable as a type of FindItemsResults. My code below keeps on generating the error "Unable to findtype [findItemsResults1]". Even if I get rid of the

    `1 operator for a nullable return, I still get errors.

    I've had this code working on a different Exchange 2010 server, so am not sure why it is now going wrong.

    Please advise.





    void][Reflection.Assembly]::LoadFile($installpath + "\Microsoft.Exchange.WebServices.dll")



    New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010)



    = [System.URI]"https://MyExchangeFQDN/ews/exchange.asmx"






    [ADSI]("LDAP://<SID=" + $windowsIdentity.user.Value + ">")



    [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service, [Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox)



    $inbox.TotalCount -le 0 )


    # Nothing to do



    "The total number of messages are "


    $inbox.TotalCount + " "

    # Iterate through each message in the Inbox...



    New-Object Microsoft.Exchange.WebServices.Data.ItemView($inbox.TotalCount)



    ] $results = $inbox.FindItems($view)

    IT Support/Everything

    Wednesday, May 22, 2013 7:27 AM

All replies

  • A few things

    $view = New-Object Microsoft.Exchange.WebServices.Data.ItemView($inbox.TotalCount)

    This is not a good idea as throttling will prevent you returning any more then 1000 items at a time, if you trying to interate through Inbox Item you should always page the item.

    You also don't need to cast the results of findItems just using something like

    #Define ItemView to retrive just 1000 Items    
    $ivItemView =  New-Object Microsoft.Exchange.WebServices.Data.ItemView(1000)    
    $fiItems = $null    
        $fiItems = $service.FindItems($Inbox.Id,$ivItemView)    
        foreach($Item in $fiItems.Items){      
    				#Process Item          
        $ivItemView.Offset += $fiItems.Items.Count    
    }while($fiItems.MoreAvailable -eq $true) 


    Wednesday, May 22, 2013 10:41 AM