Exchange Powershell script gives dr Watson RRS feed

  • Question

  • Hi,

    When running a powershell (scheduled) through a batchfile I get a dr. Watson error:

    WARNING: An unexpected error has occurred and a Watson dump is being generated:
     Operation is not valid due to the current state of the object.
    Get-ActiveSyncDeviceStatistics : Operation is not valid due to the current
    state of the object.
    At D:\Scripts\ActiveSyncExport.ps1:34 char:27
    + $Devices = $Mailboxes | %{Get-ActiveSyncDeviceStatistics -Mailbox
    $_.Identity} | ...
    +                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [Get-ActiveSyncDeviceStatistic
       s], InvalidOperationException
        + FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.Excha

    But when I run this script from the Exchange Management Shell manually it works normally.

    I tried this in the script, but that doesn't work either:

    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Authentication Kerberos
    Import-PSSession $Session

    The servers are running Exchange 2010 SP3 with rollup 2.

    It looks like a sort of buffer overflow error.

    Does anybody know a solution?

    Wednesday, February 19, 2014 12:36 PM

All replies

  • I get these too on boxes that have the Exchange console installed, but aren't the CAS or mailbox servers themselves. I can't seem to find any solutions to this, but a lot of people are having this issue. It seems to only happen to a few powershell cmdlets.

    I've read somewhere that it may be a .NET issue but not sure where to begin. Running Powershell 2 

    Brandon Carder

    Thursday, July 24, 2014 6:42 PM
  • Me too.. same problem, same "Get-ActiveSyncDeviceStatistics" command..  I've tried on several servers, and my scripts run fine on the Exchange servers themselves, just wont run on the servers we have designated as the ones to run scheduled / repetitive tasks..

    No ideas??

    Wednesday, February 25, 2015 2:30 PM
  • Hi Guys,

    this is probably due to the usual serialization / deserialization issue. Try importing the commands with this function script.

    Another note - try to avoid using Exchange Cmdlets in combination with ForEach-Object uses - go straight through the pipeline instead:

    $mb = Get-Mailbox | Where { "Whatever Condition you need to apply" } | Select -ExpandProperty Identity | %{ $_.ToString() }
    Get-ActiveSyncDevice | Where { $mbl -contains $_.UserDisplayName } | Get-ActiveSyncDeviceStatistics

    Otherwise you'll exceed session limits, whether on the server or not.


    There's no place like

    • Edited by FWN Friday, February 27, 2015 1:24 PM
    Friday, February 27, 2015 1:11 PM