gpt4 book ai didi

vb.net - 使用VB.Net禁用Exchange 2010邮箱

转载 作者:行者123 更新时间:2023-12-03 00:02:35 25 4
gpt4 key购买 nike

我正在尝试使用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 cannot be null. Parameter name: serverSetting



堆栈跟踪可能很难读取,但第一印象是您正在将null / Nothing值传递给需要某些实例的函数。

我不熟悉Exchange对象,并且您没有分享哪条线引发错误,但是我最好的阅读代码的猜测是这条线引发错误:
myRunSpace = RunspaceFactory.CreateRunspace(rsConfig)

您可以通过在顶部附近更改此行来解决此问题:
Dim rsConfig As RunspaceConfiguration

对此:
Dim rsConfig As New RunspaceConfiguration

不幸的是,我怀疑这只会帮助您发现下一个错误。我希望有一个原因需要将配置对象传递给该方法,并且默认实例可能不够好。

关于vb.net - 使用VB.Net禁用Exchange 2010邮箱,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20341133/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com