locked
all the objects are not being passed through the pipeline RRS feed

  • Question

  • The output is from 1 of the 5 transport servers that I have.

    if I do $mailq...the result is all the queues on 1 server. How do I get the results of 5 servers?

    $ExServer gives me the names of 5 transport servers.

    function sendmail($body){ $SmtpClient = new-object system.net.mail.smtpClient $MailMessage = New-Object system.net.mail.mailmessage $SmtpClient.Host = "smtp.company.com" $mailmessage.from = "Queues.Exchange@company.com" $mailmessage.To.add("user@domain.net") $mailmessage.Subject = “TEST TEST TEST Hub Transport Queue Blockage - PLEASE INVESTIGATE” $MailMessage.IsBodyHtml = $true $mailmessage.Body = $body $smtpclient.Send($mailmessage) } #Variables $time = get-date -format g $Queue_length = 1 $MailQfile = "C:\Temp\MailQFile.htm" + "$time" $ExServer = Get-TransportServer |Sort-Object name |select -Property name foreach ($Server in $ExServer) { $messageCount = get-queue -Server $Server.Name | ForEach-Object -Begin {$total=0} -process {$total+=$_.messagecount} -end {$total} $mailq = $Server.Name |get-queue

    }


    Tuesday, August 15, 2017 5:44 PM

Answers

  • [array]$mailq += $Server.Name |get-queue
    • Proposed as answer by jrv Tuesday, August 15, 2017 6:14 PM
    • Marked as answer by Tiri2014 Tuesday, August 15, 2017 6:27 PM
    Tuesday, August 15, 2017 5:52 PM

All replies

  • [array]$mailq += $Server.Name |get-queue
    • Proposed as answer by jrv Tuesday, August 15, 2017 6:14 PM
    • Marked as answer by Tiri2014 Tuesday, August 15, 2017 6:27 PM
    Tuesday, August 15, 2017 5:52 PM
  • This would be how to do this in PowerShell V2 and later.

    $mailprops = @{
    	From = 'Queues.Exchange@company.com'
    	To = 'user@domain.net'
    	Subject = 'TEST TEST TEST Hub Transport Queue Blockage - PLEASE INVESTIGATE'
    	BodyAsHtml = $true
    	SmtpServer  = 'smtp.company.com'
    }
    $MailQfile = 'C:\Temp\MailQFile{0}.htm' -f (get-date -format g)
    $ExServer = Get-TransportServer | Sort-Object name
    foreach ($Server in $ExServer) {
    	$q = get-queue -Server $Server.Name
    	$total += $q.messagecount
    	[array]$mailq += $q
    }
    # create body code goes here
    Send-MailMessage @mailprops -Body $body


    \_(ツ)_/

    Tuesday, August 15, 2017 6:23 PM