簡體   English   中英

使用VB.Net禁用Exchange 2010郵箱

[英]Disable an Exchange 2010 mailbox using VB.Net

我正在嘗試使用VB.Net禁用Exchange 2010中的郵箱。

    Dim rsConfig As RunspaceConfiguration
    rsConfig = RunspaceConfiguration.Create()
    Dim snapInException As PSSnapInException = Nothing
    Dim info As PSSnapInInfo = rsConfig.AddPSSnapIn("microsoft.exchange.management.powershell.e2010", snapInException)
    Dim myRunSpace As Runspace
    myRunSpace = RunspaceFactory.CreateRunspace(rsConfig)
    myRunSpace.Open()
    Dim pipeLine As Pipeline
    pipeLine = myRunSpace.CreatePipeline()
    Dim sScript As String = "disable-mailbox -Identity 'Bill Smith' -Confirm:$false"
    pipeLine.Commands.AddScript(sScript)
    pipeLine.Invoke()
    pipeLine.Dispose()

我收到此錯誤:

  System.Management.Automation.CmdletInvocationException was unhandled
  Message=Value cannot be null.
Parameter name: serverSettings
  Source=System.Management.Automation
  WasThrownFromThrowStatement=False
  StackTrace:
       at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input, Hashtable errorResults, Boolean enumerate)
       at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][] commandRedirections, FunctionContext funcContext)
       at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame)
       at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
  InnerException: System.ArgumentNullException
       Message=Value cannot be null.
Parameter name: serverSettings
       ParamName=serverSettings
       Source=Microsoft.Exchange.Configuration.ObjectModel
       StackTrace:
            at Microsoft.Exchange.Configuration.Tasks.TaskVerboseStringHelper.GetADServerSettings(String cmdletName, ADServerSettings serverSettings)
            at Microsoft.Exchange.Configuration.Tasks.TaskVerboseStringHelper.GetADServerSettings(ADServerSettings serverSettings)
            at Microsoft.Exchange.Configuration.Tasks.Task.LogCmdletIterationEvent()
            at Microsoft.Exchange.Configuration.Tasks.Task.BeginProcessing()
            at System.Management.Automation.Cmdlet.DoBeginProcessing()
            at System.Management.Automation.CommandProcessorBase.DoBegin()
       InnerException: 

有人可以幫忙嗎? 提前致謝。

這是錯誤的重要部分:

Message = Value不能為null。 參數名稱:serverSetting

堆棧跟蹤可能很難讀取,但第一印象是您正在將null / Nothing值傳遞給需要某些實例的函數。

我不熟悉Exchange對象,並且您沒有分享哪條線引發錯誤,但是我最好的閱讀代碼的猜測是這條線引發錯誤:

myRunSpace = RunspaceFactory.CreateRunspace(rsConfig)

您可以通過更改頂部附近的這一行來解決此問題:

Dim rsConfig As RunspaceConfiguration

對此:

Dim rsConfig As New RunspaceConfiguration

不幸的是,我懷疑這只會幫助您發現下一個錯誤。 我期望有一個原因需要將配置對象傳遞給該方法,並且默認實例可能不夠好。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM