【问题标题】:PowerShell module to connect to exchange premisePowerShell 模块连接到交换场所
【发布时间】:2019-05-15 03:58:35
【问题描述】:

使用自定义模块时,无法从 powershell 运行 Exchange cmdlet。

大家好,

下面的函数在使用脚本连接时可以正常工作;但是,当变成一个模块时,它会加载并且所有但不识别诸如 get-mailbox 之类的 cmdlet。

Function ConnectToExchange ([string]$eXCHServer, $myCred){
  $Session = "" 

  if(!$Session)
  {      
    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $eXCHServer -Credential $myCred -AllowRedirection

    Import-PSSession $Session -AllowClobber 


    if ($Session.State -eq "Closed")
    {
      return
    }
 }
}#end function

【问题讨论】:

  • 你可以试试Import-Module -PSSession $Sesion -Scope Global
  • 你好,Prasoon。尝试时出现以下错误。 Import-Module :无法使用指定的命名参数解析参数集。在 line:14 char:9 + Import-Module -PSSession $Session -Scope Global + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Import-Module], ParameterBindingException + FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.PowerShell.Commands.ImportModuleCommand
  • 尝试在全局范围内导入您的模块。 Import-Module -Name YourModule -Scope Global
  • 不,仍然无法识别 cmdlet。

标签: powershell module exchange-server


【解决方案1】:

我一直在努力解决同样的问题。当您连接到交换时,它会创建一个存储命令的临时模块,我不知道为什么,但它不会加载它们。

为连接函数分配一个变量,然后使用它来查找和加载模块似乎可行。

$exc = ConnectToExchange

$excmod = Get-ChildItem -Path $env:userprofile -Filter $exc.name -recurse -Force -ErrorAction SilentlyContinue | select FullName

Import-Module $excmod.fullname

【讨论】:

  • 谢谢!这周我会尝试你的建议并报告结果。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-11
  • 2018-08-31
  • 2013-05-24
相关资源
最近更新 更多