0

我有一个 ASP.NET 3.5 应用程序运行 Powershell 脚本来添加/更新 Exchange 邮箱。大多数 Powershell 命令都运行良好,但其中两个迄今为止导致了错误:get-calendarprocessing 和 set-calendarprocessing,它们获取或设置分配给安排房间的用户。错误是 System.Management.Automation.CmdletInvocationException:由于对象的当前状态,操作无效。当我从 Exchange 命令行管理程序运行命令时,它们运行良好。我们已经修补并重新启动了 Exchange 服务器。

命令示例:get-calendarprocessing Room.1 | select -expand bookinpolicy(或类似的变体)

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          
4

0 回答 0