Hankinater
asked on
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
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
}
ASKER
Simon,
Thanks for the quick response. I rewrote the script to include the expression. However the result is encapsulated in brackets:
Thanks again!
Thanks for the quick response. I rewrote the script to include the expression. However the result is encapsulated in brackets:
$_.Identity.ToString Identity MessageCountAny idea how to get rid of the curly brackets? Also can I make the column header read Server, Queue?
().Split("\")
-------------------- -------- ------------
{BLAH0, 452962} BLAH0\452962 0
{BLAH0, 457544} BLAH0\457544 6
{BLAH0, 458092} BLAH0\458092 1
{BLAH0, Submi... BLAH0\Submission 9
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
}
ASKER
Sorry, I was looking at output to screen. Actually the output has double quotes around the split name. Like "BLAH0 452962"
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.
Simon.
ASKER
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
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
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.
Simon.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Michael, thanks a bunch for the help...it works perfectly now.
ASKER
Thanks Michael,
The edited code is below
Hank
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
}
Something like this in your select line should do it..
expression={$_.Identity.To
Do post back the completed script, as it may help others.
Simon.