servers list in a domain

  • 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

  • you can manipulate the results in powershell

    [System.Data.Sql.SqlDataSourceEnumerator]::Instance.GetDataSources() | SELECT ServerName | Format-Table -HideTableHeaders

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • 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

  • 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!!!

  • [System.Data.Sql.SqlDataSourceEnumerator]::Instance.GetDataSources() | SELECT ServerName.Trim() | Format-Table -HideTableHeaders

    This threw a syntactic error

  • smmkr17 (12/2/2015)


    [System.Data.Sql.SqlDataSourceEnumerator]::Instance.GetDataSources() | SELECT ServerName.Trim() | Format-Table -HideTableHeaders

    This 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!!!

  • This is the script.It extracts all servers within a domain.

  • 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!!!

  • ([System.Data.Sql.SqlDataSourceEnumerator]::Instance.GetDataSources()).ServerName

    Although won't work if you need more fields from the output of GetDataSources()

  • 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


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Viewing 10 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic. Login to reply