[英]Exchange cmdlets when called from remote machine
I have one exchange server and a windows 7 machine. 我有一台交换服务器和一台Windows 7计算机。
WRT remote execution WRT远程执行
Server - Exchange Server (Win server 2012) Client - Win 7 machine 服务器-Exchange Server(Win Server 2012)客户端-Win 7计算机
I want to run scripts which are present in client machine on remote machine (exchange/ win server 2012). 我想运行远程计算机(exchange / win server 2012)上客户端计算机中存在的脚本。 But these are failing with error cmdlets not found.
但是这些失败,并且未找到错误cmdlet。
So to check quickly i tried to invoke normal powershell cmdlets as well as exchange cmdlets and found that only exchange cmdlets are failing. 因此,为了快速检查,我尝试调用普通的powershell cmdlet以及交换cmdlet,结果发现只有交换cmdlet失败了。 However if i run same cmdlet on server (exchange) it gives me expected output.
但是,如果我在服务器(交换)上运行相同的cmdlet,则可以得到预期的输出。
Questions 问题
Attached below sample test outputs. 附在样本测试输出下方。
Help me how to proceed further !! 帮助我如何进一步进行!
On remote client (Win 7 machine) 在远程客户端(Win 7计算机)上
PS C:\Users\Administrator> invoke-command -Session $session -ScriptBlock { ls }
returns: 收益:
Directory: C:\Users\Administrator\Documents
Mode LastWriteTime Length Name PSComputerName
---- ------------- ------ ---- --------------
d----- 12/2/2018 12:10 PM WindowsPowerShell 10.76.68.251
But the Exchange cmdlets do not work 但是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
Server - Exchange / Server 2012 服务器-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)
Test with Exchange Server URL in Connection URI 在连接URI中测试Exchange Server URL
Test 1 测试1
PS C:\Users\Administrator> $session1 = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://10.76.68.251/PowerShell/ -Authentication Kerberos -Credential $credential
Error: 错误:
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
Test 2 测试2
PS C:\Users\Administrator> $session1 = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://10.76.68.251/PowerShell/ -Credential $credential
Error: 错误:
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
Yes, they do, this is a common practice, but what you are doing is not complete enough. 是的,他们这样做,这是一种常见的做法,但是您做的还不够完整。
You have to use PSRemoting to do this and that is well documented by Microsoft for not only Exchange on prom but for Exchange Online. 您必须使用PSRemoting来执行此操作,并且Microsoft充分记录了该信息不仅适用于舞会上的Exchange,还适用于Exchange Online。
Connect to Exchange servers using remote PowerShell 使用远程PowerShell连接到Exchange服务器
Connect-O365 1.5.4 Connect-O365 1.5.4
If you are using the PowerShell ISE, you can take either of these approaches, just remember to hit that Refresh button on the Commands tabs to see the cmdlets reflected. 如果您使用的是PowerShell ISE,则可以采用以下两种方法之一,只需记住单击“命令”选项卡上的“刷新”按钮以查看所反映的cmdlet。
How To–Load Exchange Management Shell into PowerShell ISE 如何将Exchange命令行管理程序加载到PowerShell ISE中
Adding Exchange Shell items to PowerShell ISE 将Exchange Shell项目添加到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"
)
If you are using the console host, just remove all the ISE stuff. 如果您使用控制台主机,请删除所有ISE东西。
$ExSession= New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://exserver.contoso.com/PowerShell/ -Authentication Kerberos
Import-PSSession $ExSession
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.