Skip to content

Instantly share code, notes, and snippets.

@tostka
Created September 22, 2017 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tostka/f647c265a5e8e9a251e6ecd7ed382723 to your computer and use it in GitHub Desktop.
Save tostka/f647c265a5e8e9a251e6ecd7ed382723 to your computer and use it in GitHub Desktop.
<# Exchange HubTransport queue snippet for dumping queued external delivery domain details,
for all hub servers in the local AD Site. (Exchange 2010 version)
Update the $probdom to a target fqdn, and run it.
#>
$probdom='badmaildelivery.com' ;
$Site=[System.DirectoryServices.ActiveDirectory.ActiveDirectorySite]::GetComputerSite().Name ;
$Banner="== v Site:$($Site.toupper()) - MSGS QUEUED TO $($probdom) PER HUB: v ==" ;
write-host -foregroundcolor green "`n$((get-date).ToString('HH:mm:ss')):$($Banner)" ;
$hubsl=Get-ExchangeServer | where { $_.isHubTransportServer -eq $true -and $_.Site -match ".*\/$($Site)$"} | select -expand name ;
foreach($hub in $hubsl){ write-host -foregroundcolor green "$((get-date).ToString('HH:mm:ss')):----$($hub):" ;
[console]::ResetColor() ;
$qs=(get-queue -server $hub | ?{$_.Nexthopdomain -eq $probdom}).identity ;
if($qs) {
foreach ($q in $qs) {
get-message -IncludeRecipientInfo -queue $q | select Identity,DateReceived,FromAddress,@{Name='Recipients';
Expression={$_.Recipients| select -expand address}},Status,Queue,Subject | sort Identity | fl ;
} ;
} else { "(nothing on $($hub))" };
[console]::ResetColor() ;
} ;
write-host -foregroundcolor green "$((get-date).ToString('HH:mm:ss')):$($Banner.replace(' v ',' ^ '))`n" ;
<# same code unwrapped into a paste-able 1-liner
$probdom='crmdatadeals.com' ;$Site=[System.DirectoryServices.ActiveDirectory.ActiveDirectorySite]::GetComputerSite().Name ;$Banner="== v Site:$($Site.toupper()) - MSGS QUEUED TO $($probdom) PER HUB: v ==" ;write-host -foregroundcolor green "`n$((get-date).ToString('HH:mm:ss')):$($Banner)" ;$hubsl=Get-ExchangeServer | where { $_.isHubTransportServer -eq $true -and $_.Site -match ".*\/$($Site)$"} | select -expand name ;foreach($hub in $hubsl){ write-host -foregroundcolor green "$((get-date).ToString('HH:mm:ss')):----$($hub):" ; [console]::ResetColor() ; $qs=(get-queue -server $hub | ?{$_.Nexthopdomain -eq $probdom}).identity ; if($qs) { foreach ($q in $qs) { get-message -IncludeRecipientInfo -queue $q | select Identity,DateReceived,FromAddress,@{Name='Recipients';Expression={$_.Recipients| select -expand address}},Status,Queue,Subject | sort Identity | fl ; } ; } else { "(nothing on $($hub))" };[console]::ResetColor() ;} ;write-host -foregroundcolor green "$((get-date).ToString('HH:mm:ss')):$($Banner.replace(' v ',' ^ '))`n" ;
#>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment