I want to retrieve all users from our HP ALM QC installation and have a Powershell script that does this. The problem is that it pads the output with spaces to, I assume, make it more readable.
This is the script
$ServerInstance = "qc-server "
$Database = "qcsiteadmin_db "
$ConnectionTimeout = 30
$Query = "select USER_NAME, FULL_NAME, EMAIL from [td].USERS"
$QueryTimeout = 120
$conn=new-object System.Data.SqlClient.SQLConnection
$ConnectionString = "Server={0};Database={1};Integrated Security=True;Connect Timeout={2}" -f $ServerInstance,$Database,$ConnectionTimeout
$conn.ConnectionString=$ConnectionString
$conn.Open()
$cmd=new-object system.Data.SqlClient.SqlCommand($Query,$conn)
$cmd.CommandTimeout=$QueryTimeout
$ds=New-Object system.Data.DataSet
$da=New-Object system.Data.SqlClient.SqlDataAdapter($cmd)
[void]$da.fill($ds)
$conn.Close()
$ds.Tables
This script gives me the following output:
USER_NAME FULL_NAME EMAIL
--------- --------- -----
user01 First Last user01@foo.com
user02 First Last user02@foo.com
user03 First Last user03@foo.com
Nicely tabulated data with lots of spaces, which makes import into Excel rather daunting...
I then tried to change my SQL-query into something that would be better suited, i.e., I tried to create a semicolon separated output since that lends itself to import rather splendidly.
$Query = "select USER_NAME + ';' + FULL_NAME + ';' + EMAIL from [td].USERS"
This did almost work, in that I got the following output:
Column1
-------
user01;First Last;user01@foo.com
user02;First Last;user02@foo.com
user03;First Last;user03@foo.com
What doesn't show is that all lines are padded at the end with spaces all the way up to position 119 - that is a lot of spaces...
So, my question at last: how can I get rid of all the spaces? Can I do it in the script above or do I need another script to use on the output of the first?