我有一个运行Powershell脚本的ASP.NET 3.5应用程序来添加/更新Exchange邮箱。大多数Powershell命令运行良好,但到目前为止其中两个命令导致错误:get-calendarprocessing和set-calendarprocessing,它们获取或设置用户来安排一个Room。错误是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