简体   繁体   English

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

[英]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 问题

  1. Won't exchange cmdlets work in remote powershell ? 交换cmdlet是否可以在远程Powershell中工作?
  2. I tried with different session type having exchange server as connection URL but facing errors there as well. 我尝试使用具有交换服务器作为连接URL的其他会话类型,但在那里也遇到错误。

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. 是的,他们这样做,这是一种常见的做法,但是您做的还不够完整。

  1. PSRemoting must properly be enabled. 必须正确启用PSRemoting。
  2. You must pass the credentials of an account that is an admin on the box and admin in Exchange 您必须在包装盒上传递管理员帐户的凭据,在Exchange中传递管理员身份

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.

相关问题 从C#运行空间调用远程Cmdlet - Calling remote Cmdlets from C# Runspace 如果我使用 enter/import-pssession cmdlet,为什么在远程计算机(使用参数)上以编程方式 (C#) 执行 powershell cmdlet 不起作用? - Why executing powershell cmdlets programmatically (C#) on remote machine (using arguments) doesn't work if I use enter/import-pssession cmdlets? 在非管理员用户下从远程运行PS cmdlet - 访问被拒绝 - Running PS cmdlets from remote under non-admin users - Access Denied 在客户端计算机上的远程计算机上启用WinRM - Enable WinRM on a remote machine from a client machine 从本地计算机到远程计算机的Powershell任务 - Powershell tasks from local machine to remote machine 从另一个脚本调用时,远程脚本失败 - Remote script fails when called from another script 远程 Powershell:从远程计算机检查时,映射的网络设备显示状态不可用 - Remote Powershell: Mappped Network device shows status unavailable when checked from remote machine 从 PowerShell 连接到远程机器 - Connecting to remote machine from PowerShell 将文件夹从远程计算机(Azure)复制到远程计算机 - Copy folder from remote machine (Azure) to remote machine 将Azure PowerShell Cmdlet加载到远程VM - Load Azure PowerShell Cmdlets onto Remote VM
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM