Hey all,
I'm trying to get a handle on some basic scripts I'm using to monitor
our systems. I can get them "functioning" correctly, but a number of
them aren't pretty. The problem seems to be that the first time a pipe
terminates within a loop, headers are written to the output. This is
fine as long as I'm adding any other text within the loop before the
first pipe output is dumped.
-Do I need to strip off the table headers somehow and manually write
them out before entering the loop (which seems counter-intuitive, as I'd
have to manually re-write the headers any time I changed the output
fields I'm looking for)?
....or...
-Is there something simple I'm missing to get my text in under the
header but before the data?
An example script is attached (it checks Exchange queues, so you'll need
appropriate security access to an Exchange 2003 server if you plan to
run it). If you run it against more than one server, it puts the first
server name above the header list. For more complex stuff, that means I
have to "doctor" the output before sending it to anyone, which is
starting to get kind of irritating. :S
--Jonathan "smthng" Kalmes
http://smthng.info
#---Begin PS Script------
#If you want to use a text file for server names,
#just uncomment the next line and comment the one after that.
#$computers = Get-Content c:\scripts\servers.txt
$computers = "Server1","Server2","Server3"
Foreach ($objItem in $computers){
Write-host $objItem -foregroundcolor Cyan
Get-wmiobject -class exchange_SMTPQueue -Namespace `
ROOT\MicrosoftExchangev2 -ComputerName $objItem | `
Select-Object LinkName,QueueName,MessageCount,Size | `
Where-Object -FilterScript {$_.MessageCount -ne 0} | `
Sort-Object QueueName
}
Read-Host -prompt "Press <Enter> to close:"
#-------End PS Script--------



