Tip: Use cmdlets to Perform One-to-Many Remote Management of Exchange 2010

PowerShell also lets you perform one-to-many remote management. Here, you must work with an elevated, administrator shell and can either invoke remote commands on multiple computers or establish remote sessions with multiple computers. When you remotely invoke commands, PowerShell runs the commands on the remote computers, returns all output from the commands, and establishes connections to the remote computers only for as long as is required to return the output. When you establish remote sessions, you can create persistent connections to the remote computers and then execute commands within the session. Any com¬mand you enter while working in the session is executed on all computers to which you are connected, whether this is 1 computer, 10 computers, or 100 computers.

Follow Our Daily Tips

RSS | Twitter | Blog | Facebook

Tell Us Your Tips

Share your tips and tweaks.

Note that WinRM must be appropriately configured on any computer you want to remotely manage. While WinRM is configured on Exchange servers and most others computers running Windows 7 and Windows Server 2008 Release 2, WinRM listeners generally are not created by default. You can create the required listeners by running winrm quickconfig.

The following command entered as a single line invokes the Get-Service and Get- Process commands on the named servers:
invoke-command -computername MailServer12, MailServer21, MailServer32 -scriptblock {get-service; get-process}

The following command establishes a remote session with the named computers:
$s = new-PSSession –computername MailServer12, MailServer21, MailServer32 –Credential Cpandl\WilliamS

When you connect to a server in this way, you use the standard PowerShell remoting configuration and are not going through the PowerShell application running on a Web server.After you establish the session, you can then use the $s session with Invoke-Command to return commands on all remote computers you are connected to.In this example, you look for stopped Exchange services on each computer:
invoke-command –session $s -scriptblock {get-service mse* | where { $_.status -eq "stopped"}}

In this example, you pipe the output of Get-Service to the Where-Object cmdlet and filter based on the Status property.As the $_ automatic variable operates on the current object in the pipeline, PowerShell examines the status of each service in turn and lists only those that are stopped in the output.

In addition to working with remote commands and remote sessions, some cmdlets have a –ComputerName parameter that lets you work with a remote computer without using Windows PowerShell remoting. PowerShell supports remote background jobs as well. A background job is a command that you run asynchronously in an interactive or noninteractive session. When you start a background job, the command prompt returns immediately and you can continue working while the job runs.

From the Microsoft Press book Microsoft Exchange Server 2010 Administrator’s Pocket Consultant by William R. Stanek.

Looking for More Tips?

For more tips on Exchange Server and other Microsoft technologies, visit the TechNet Magazine Tips library.