locked
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.

    Thanks

     

     

    [

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

    $service

    =

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

    $service

    .Url

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

    $windowsIdentity

    =

    [System.Security.Principal.WindowsIdentity]::GetCurrent()

    $aceUser

    =

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

    $inbox

    =

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

    if

    (

    $inbox.TotalCount -le 0 )

    {

    # Nothing to do

    Exit

    }

    "The total number of messages are "

    +

    $inbox.TotalCount + " "

    # Iterate through each message in the Inbox...

    $view

    =

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

    [FindItemsResults

    `1

    ] $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    
    do{    
        $fiItems = $service.FindItems($Inbox.Id,$ivItemView)    
        #[Void]$service.LoadPropertiesForItems($fiItems,$psPropset)  
        foreach($Item in $fiItems.Items){      
    				#Process Item          
        }    
        $ivItemView.Offset += $fiItems.Items.Count    
    }while($fiItems.MoreAvailable -eq $true) 

    Cheers
    Glen

    Wednesday, May 22, 2013 10:41 AM