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

Ask your 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.
This topic is 5 years and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
ITEngineer
Posts: 216
Last visit: Thu Mar 23, 2023 5:45 pm
Has voted: 4 times

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

Post by ITEngineer »

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 */
This topic is 5 years and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked