Jakub Krupa Jakub Krupa - 1 year ago 114
PowerShell Question

Get current Exchange Server

I'm using EMS. When invoking Get-ExchangeServer command I'm getting list of available Exchange servers.

Now the question:

How to get current Exchange server (the one I've invoked Get-ExchangeServer command on)?

Can anyone advice how to achieve it?

Answer Source

Use the environment variable $ENV:COMPUTERNAME to retrieve the server name of the exchange server that you are invoking the command on.

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