Executing Exchange PowerShell command in multiple servers and send the result to email?

Ask your Windows PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
ITEngineer
Posts: 145
Joined: Wed Oct 12, 2011 10:52 am

Executing Exchange PowerShell command in multiple servers and send the result to email?

Post by ITEngineer » Wed Jul 25, 2018 12:39 am

How can this code below modified so it can be run or executed for all Exchange servers rather than the current run session only?

Code: Select all

$session = New-PSSession -Configurationname Microsoft.Exchange -ConnectionURI http://PRDMAIL01-VM/PowerShell/ -Authentication Kerberos
[void] (Import-PSSession $session -AllowClobber)

$ExcServers = (Get-TransportService)
$ExcServers | ForEach-Object {Get-Queue -Server $_.Server} |
		Where-Object {($_.MessageCount -gt 0) -and ($_.Identity -notlike "*\Poison") -and ($_.Identity -notlike"*\Shadow\*")} |
		Select-Object Identity, Status, MessageCount, NextHopDomain, LastError | ft -AutoSize
So far it can only grab the email queue from PRDMAIL01-VM, but not the other 7 servers where I have in the Datacenter?

If possible, how can the result is emailed?

Thanks in advance.
/* IT Engineer */


Locked