December 1, 2015 at 11:03 am
When I run this script in a SQL job and have the output to a text extract.
Script:
[System.Data.Sql.SqlDataSourceEnumerator]::Instance.GetDataSources
This is what I see as underneath in the text extract.
1.How can I not have the 1 empty line in the text extract
2.ServerName is the column name..I dont want to show an column name in the text extract
3.----------------- <----I do not want this line in the text extract
And I find empty space after each servername (ABCD,EFGH...)on each line.I do not want this.
Empty line---->1
ServerName---->2
---------- ---->3
ABCD empty space
EFGH empty space
IJKL empty space
MNOP empty space
QRST empty space
My text extract should be a simple text file without the first 3 lines as above.
Only the servername should show with no trailing empty spaces after the servernames.
ABCD
EFGH
IJKL
MNOP
QRST
Responses are appreciated.
Thanks
December 1, 2015 at 11:47 am
you can manipulate the results in powershell
[System.Data.Sql.SqlDataSourceEnumerator]::Instance.GetDataSources() | SELECT ServerName | Format-Table -HideTableHeaders
Lowell
December 1, 2015 at 12:45 pm
This code does not remove the empty spaces after each server name.I am unable to import it into a SQL table using an SSIS package.
Thanks
December 2, 2015 at 2:28 am
Each server name is a string so you can call Trim() on them to remove any whitespace at the beginning or end of the string (you may just want to use TimeEnd() in this scenario).
Gaz
-- Stop your grinnin' and drop your linen...they're everywhere!!!
December 2, 2015 at 4:12 am
[System.Data.Sql.SqlDataSourceEnumerator]::Instance.GetDataSources() | SELECT ServerName.Trim() | Format-Table -HideTableHeaders
This threw a syntactic error
December 2, 2015 at 4:26 am
smmkr17 (12/2/2015)
[System.Data.Sql.SqlDataSourceEnumerator]::Instance.GetDataSources() | SELECT ServerName.Trim() | Format-Table -HideTableHeadersThis threw a syntactic error
It would do. Without seeing more of your script I cannot say where the Trim() should go. Anyway, either it is after the SELECT or there may be a way of doing it as part of the SELECT or Format-Table.
Gaz
-- Stop your grinnin' and drop your linen...they're everywhere!!!
December 2, 2015 at 10:41 am
This is the script.It extracts all servers within a domain.
December 2, 2015 at 12:23 pm
sqlnewbie17 (12/2/2015)
This is the script.It extracts all servers within a domain.
I see no script!!!
Gaz
-- Stop your grinnin' and drop your linen...they're everywhere!!!
December 4, 2015 at 12:10 pm
([System.Data.Sql.SqlDataSourceEnumerator]::Instance.GetDataSources()).ServerName
Although won't work if you need more fields from the output of GetDataSources()
December 4, 2015 at 12:37 pm
i think the OP might be copy/pasting from the Powershell ISE and getting whitespace tot he right of the values, but that's a product of the results panel, and not the command.
Lowell
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply