【问题标题】:Get current Exchange Server获取当前的 Exchange 服务器
【发布时间】:2016-12-09 07:43:41
【问题描述】:

我正在使用 EMS。调用 Get-ExchangeServer 命令时,我正在获取可用 Exchange 服务器的列表。

现在的问题:

如何获取当前的 Exchange 服务器(我调用过 Get-ExchangeServer 命令的那个)?

谁能建议如何实现它?

【问题讨论】:

    标签: powershell exchange-server


    【解决方案1】:

    使用环境变量$ENV:COMPUTERNAME 检索您正在调用命令的交换服务器的服务器名称。

    Invoke-Command -ComputerName Exchange.domain.com `
                   -ScriptBlock {Get-ExchangeServer -Identity $ENV:COMPUTERNAME} `
                   -Credential (Get-Credential)
    

    【讨论】:

    • 是的,我之前考虑过使用$ENV:COMPUTERNAME,但我是在远程 PS 会话中使用它,在这种情况下它会返回我的本地计算机名称。但是您为我指出了正确的方向(即使用Invoke-Command 在远程Exchange 服务器上获取$ENV:COMPUTERNAME 的值,然后在调用Get-ExchangeServer 时使用它)。非常感谢您的帮助:)
    【解决方案2】:
    • 简答:

      Get-ExchangeServer | select PSComputerName,OriginatingServer -Unique

    • 解释(长答案):

      命令Get-ExchangeServer的输出,已经有你感兴趣的成员了:

    PS:\ > Get-ExchangeServer | Get-Member
    
    Name                    MemberType     (my explanation)
    ----                    ----------     -----------------
    .                       .              .
    PSComputerName          NoteProperty   It's the current ExchangeServer (the one that actually your command has been executed on)
    OriginatingServer       Property       It's the current DomainController (the one that your ExchangeServer has used for the query)
    .                       .              .
    

    然后,使用 EMS 或 PSRemoting,它总是返回你想要的。但是,如果您的环境中有多个 ExchangeServer,则输出可能包含具有相同值的多行。喜欢:

    PS:\ > Get-ExchangeServer | select PSComputerName,OriginatingServer
    
    PSComputerName OriginatingServer      
    -------------- -----------------      
    exch-srv2      dc3.contoso.com
    exch-srv2      dc3.contoso.com
    .              .
    

    这就是为什么您可以在执行Select 时使用-unique,以避免输出中出现重复行。

    PS:\ > Get-ExchangeServer | select PSComputerName,OriginatingServer -Unique
    
    PSComputerName OriginatingServer      
    -------------- -----------------      
    exch-srv2      dc3.contoso.com
    

    【讨论】:

      猜你喜欢
      • 2016-12-04
      • 2020-09-03
      • 2018-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多