【问题标题】:Exchange cmdlets when called from remote machine从远程计算机调用时交换 cmdlet
【发布时间】:2019-05-22 11:45:27
【问题描述】:

我有一台交换服务器和一台 Windows 7 机器。

W.R.T 远程执行

服务器 - Exchange 服务器(Win server 2012) 客户端 - Win 7 机器

我想在远程机器(exchange/win server 2012)上运行客户端机器中存在的脚本。但是这些都失败了,找不到错误 cmdlet。

所以为了快速检查,我尝试调用普通的 powershell cmdlet 以及交换 cmdlet,发现只有交换 cmdlet 失败。但是,如果我在服务器(交换)上运行相同的 cmdlet,它会给我预期的输出。

问题

  1. Exchange cmdlet 不能在远程 powershell 中工作吗?
  2. 我尝试了使用交换服务器作为连接 URL 的不同会话类型,但在那里也遇到了错误。

附在下面的示例测试输出。

帮助我如何进一步进行!

在远程客户端(Win 7 机器)

PS C:\Users\Administrator> invoke-command -Session $session -ScriptBlock { ls }

返回:

Directory: C:\Users\Administrator\Documents

Mode        LastWriteTime       Length Name        PSComputerName
----        -------------        ------ ----        --------------
d-----      12/2/2018  12:10 PM  WindowsPowerShell  10.76.68.251

但 Exchange cmdlet 不起作用

PS C:\Users\Administrator> invoke-command -Session $session -ScriptBlock { Get-Mailbox }
The term 'Get-Mailbox' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
    + CategoryInfo          : ObjectNotFound: (Get-Mailbox:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
    + PSComputerName        : 10.76.68.251

服务器 - Exchange / Server 2012

PS C:\Users\Administrator\Downloads\custom scripts> Get-Mailbox

Name                      Alias                ServerName       ProhibitSendQuota
----                      -----                ----------       -----------------
Administrator             Administrator        win-j1uti0rc7qp  Unlimited
DiscoverySearchMailbox... DiscoverySearchMa... win-j1uti0rc7qp  50 GB (53,687,091,200 bytes)

使用连接 URI 中的 Exchange Server URL 进行测试

测试 1

PS C:\Users\Administrator> $session1 = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://10.76.68.251/PowerShell/ -Authentication Kerberos -Credential $credential

错误:

New-PSSession : [10.76.68.251] Connecting to remote server 10.76.68.251 failed with the following error message : The
WinRM client cannot process the request. Kerberos authentication cannot be used when the destination is an IP address.
Specify a DNS or NetBIOS destination or specify Basic or Negotiate authentication. For more information, see the
about_Remote_Troubleshooting Help topic.

At line:1 char:13
+ $session1 = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri h ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo: OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotingTransportException
    + FullyQualifiedErrorId : -2144108277,PSSessionOpenFailed

测试 2

PS C:\Users\Administrator> $session1 = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://10.76.68.251/PowerShell/  -Credential $credential

错误:

New-PSSession : [10.76.68.251] Connecting to remote server 10.76.68.251 failed with the following error message : The
WinRM client cannot process the request. It cannot determine the content type of the HTTP response from the
destination computer. The content type is absent or invalid. For more information, see the
about_Remote_Troubleshooting Help topic.
At line:1 char:13
+ $session1 = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri h ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession],PSRemotingTransportException
    + FullyQualifiedErrorId : -2144108297,PSSessionOpenFailed

【问题讨论】:

    标签: powershell exchange-server exchangewebservices powershell-remoting


    【解决方案1】:

    是的,他们这样做,这是一种常见的做法,但你所做的还不够完整。

    1. PSRemoting 必须正确启用。
    2. 您必须通过 作为盒子上的管理员和管理员的帐户的凭据 交流

    您必须使用 PSRemoting 来执行此操作,Microsoft 对此进行了详细记录,不仅适用于 Exchange on prom,而且适用于 Exchange Online。

    Connect to Exchange servers using remote PowerShell

    Connect-O365 1.5.4

    如果您使用的是 PowerShell ISE,则可以采用这两种方法中的任何一种,只需记住点击“命令”选项卡上的“刷新”按钮即可查看反映的 cmdlet。

    How To–Load Exchange Management Shell into PowerShell ISE

    Adding Exchange Shell items to PowerShell ISE

    $psISE.CurrentPowerShellTab.AddOnsMenu.SubMenus.Add(
        "Connect to Exchange @ Contoso", {
            $ExSession= New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://exserver.contoso.com/PowerShell/ -Authentication Kerberos
            Import-PSSession $ExSession
        },
        "Control+Alt+1"
    )
    $psISE.CurrentPowerShellTab.AddOnsMenu.SubMenus.Add(
        "Connect to Exchange On-Premise", {
            Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
            . $env:ExchangeInstallPath\bin\RemoteExchange.ps1
            Connect-ExchangeServer –auto
                },
        "Control+Alt+2"
    )
    $psISE.CurrentPowerShellTab.AddOnsMenu.SubMenus.Add(
        "Connect to Exchange Online", {
            $o365Cred= Get-Credential
            $o365Session= New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $o365Cred -Authentication Basic -AllowRedirection
            Import-PSSession $o365Session
        },
        "Control+Alt+3"
    )
    

    如果您使用的是控制台主机,只需删除所有 ISE 内容。

    $ExSession= New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://exserver.contoso.com/PowerShell/ -Authentication Kerberos
    Import-PSSession $ExSession
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-09
      • 2022-01-16
      • 2013-09-01
      • 2015-08-05
      • 2011-12-02
      相关资源
      最近更新 更多