• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 590
  • Last Modified:

I need to include the ServerName in the output when running a "Get-Queue" PowerShell script.

I have a script that runs every 2 minutes against our hub servers.  It gives me the queues and their message counts.  I use that data in a dashboard.  The "identity" values are <ServerName>/<QueueName>, I want to be able to create another column in my CSV file with server name only.  I've tried several things and I'm getting kind of frustrated.  Below is the script that I use now.  I have it create a CSV file for each server...which is working for me.

Having the ServerName value in a column by itself gives me more flexibility on how I display the data in the dashboard.

Any assistance you can provide would be appreciated!

Thanks,
Hank
$serverlist = @("BLAH0", "BLAH1", "BLAH2", "BLAH3")
     foreach ($server in $serverlist) {
          Get-Queue -Server $server | Select $server, * |Export-Csv -NoTypeInformation "E:\$server.csv" -Verbose 
start-sleep -second 2
 
}

Open in new window

0
Hankinater
Asked:
Hankinater
  • 5
  • 3
1 Solution
 
MesthaCommented:
Do a split on the identity. You may end up stuck with both parts of the queue identity though.

Something like this in your select line should do it..
expression={$_.Identity.ToString().Split("\")

Do post back the completed script, as it may help others.

Simon.
0
 
HankinaterAuthor Commented:
Simon,
Thanks for the quick response. I rewrote the script to include the expression. However the result is encapsulated in brackets:
$_.Identity.ToString    Identity                          MessageCount
().Split("\")
--------------------            --------                            ------------
{BLAH0, 452962}        BLAH0\452962            0
{BLAH0, 457544}        BLAH0\457544            6
{BLAH0, 458092}        BLAH0\458092            1
{BLAH0, Submi...        BLAH0\Submission    9
Any idea how to get rid of the curly brackets?  Also can I make the column header read Server, Queue?
Thanks again!

$serverlist = @("BLAH0", "BLAH1", "BLAH2", "BLAH3")
$expression = {$_.Identity.ToString().Split("\")}
     foreach ($server in $serverlist) {
          Get-Queue -Server $server | Select $expression, identity, messagecount |Export-Csv -NoTypeInformation "E:\$server.csv" -Verbose 
start-sleep -second 2
 
}

Open in new window

0
 
HankinaterAuthor Commented:
Sorry, I was looking at output to screen.  Actually the output has double quotes around the split name.  Like "BLAH0 452962"
0
Improved Protection from Phishing Attacks

WatchGuard DNSWatch reduces malware infections by detecting and blocking malicious DNS requests, improving your ability to protect employees from phishing attacks. Learn more about our newest service included in Total Security Suite today!

 
MesthaCommented:
My PS skills aren't too hot, but I know someone who is and is a member here. Let me see if he can assist.

Simon.
0
 
HankinaterAuthor Commented:
Thanks Simon for getting a step closer.

FYI, I was able to  change the expression to add a comma where th "\" was, so if I can get the double quotes to disapear I'd be ready to go.

Thanks again
0
 
MesthaCommented:
Another thought I had was to call the server list in a different way, rather than your static list, and then possibly use that information. However I have sought assistance, lets see if he is available and can post.

Simon.
0
 
Michael B. SmithExchange & Active Directory ExpertCommented:
Mestha's (Simon's) ideas are pretty close. You just have to be careful how you select the appropriate fields and export them. For example (and this should allow you to get to where you need to be):

get-queue | select @{name="Server"; expression={$s = $_.identity.ToString();$s.SubString(0, $s.IndexOf("\"))}}, *

Thanks,
Michael
0
 
HankinaterAuthor Commented:
Michael, thanks a bunch for the help...it works perfectly now.  
0
 
HankinaterAuthor Commented:
Thanks Michael,

The edited code is below

Hank
$serverlist = @("BLAH0", "BLAH1", "BLAH2", "BLAH3")
     foreach ($server in $serverlist) {
          Get-Queue -Server $server | select @{name="Server"; expression={$s = $_.identity.ToString();$s.SubString(0, $s.IndexOf("\"))}}, *
 |Export-Csv -NoTypeInformation "E:\$server.csv" -Verbose 
start-sleep -second 2
 
}

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Improved Protection from Phishing Attacks

WatchGuard DNSWatch reduces malware infections by detecting and blocking malicious DNS requests, improving your ability to protect employees from phishing attacks. Learn more about our newest service included in Total Security Suite today!

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now