0

I have an ASP.NET 3.5 application running Powershell scripts to add/update Exchange mailboxes. Most of the Powershell commands work great, but two of them so far have caused an error: get-calendarprocessing and set-calendarprocessing, which get or set users assigned to schedule a Room. The error is System.Management.Automation.CmdletInvocationException: Operation is not valid due to the current state of the object. When I run the commands from the Exchange Management Shell, they work fine. We have patched and rebooted the Exchange server.

Command example: get-calendarprocessing Room.1 | select -expand bookinpolicy (or similar variations)

Private Function RunScript(ByVal ScriptFileName As String, ByVal Arguments() As String) As Collection(Of PSObject)
    Dim sb As New StringBuilder
    Dim strScript As String

    ' create Powershell runspace and open
    If psRunspace Is Nothing Then
        psRunspace = InitializeRunspace()
    End If

    'Grab Powershell script from text (.ps1) file
    strScript = File.ReadAllText(ScriptFileName)

    'inject the arguments into the script
    strScript = InsertArguments(strScript, Arguments)
    Logging.LogMessage(strScript)

    'Open the runspace and create a pipeline if it's not already open
    If psRunspace.RunspaceStateInfo.State = RunspaceState.BeforeOpen Then
        psRunspace.Open()
    End If

    Dim MyPipeline As Pipeline = psRunspace.CreatePipeline()
    MyPipeline.Commands.AddScript(strScript)

    Try
        Dim psResults As Collection(Of PSObject)
        psResults = MyPipeline.Invoke()     'ERRORS HERE       

        Return psResults

    Catch ex As Exception
        Logging.LogMessage(ex.Message)
        Throw ex
    End Try

End Function          
Kelly
  • 945
  • 2
  • 18
  • 31
  • See if this is helpful: http://stackoverflow.com/questions/10697194/operation-is-not-valid-due-to-the-current-state-of-the-object-when-i-select-dro/10885701#10885701 – Yuriy Galanter May 01 '13 at 21:51
  • No, it unfortunately did not help. This is occurring in a web service, but I did add those web.config settings in my test web application just in case. – Kelly May 02 '13 at 18:06
  • Update: I had someone do a complete reinstall of Exchange on the server and then it worked. – Kelly Jun 10 '13 at 16:52

0 Answers0