从远程计算机调用时交换cmdlet

时间:2018-12-22 09:03:12

标签: powershell exchange-server exchangewebservices powershell-remoting

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

W.R.T远程执行

服务器-Exchange Server(Win Server 2012) 客户端-Win 7计算机

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

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

问题

  1. 交换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

1 个答案:

答案 0 :(得分:0)

是的,这是很常见的做法,但是您做的还不够完整。

  1. PSRemoting必须正确启用。
  2. 您必须通过     框上为admin且帐户为admin的帐户的凭据     交换

您必须使用PSRemoting来执行此操作,并且Microsoft充分证明,这不仅适用于舞会上的Exchange,还适用于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