SQL Server/Instance List

  • How do I automatically detect the list of all SQL servers/instance within a specific domain having 2000 ,2005 ,2008,2012 sql servers and dump all the servernames to a text file and automate this process.

    Thanks

    I havefound this powershell script online.

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

    I have scheduled it as part of a SQL job and it directs output to a text file.

    But it gives me a list of columns servername,version etc,...

    How do I only get the servername column without the servername heading in the text extract.

    Thanks

    Currently the text extract looks as underneath when I run the powershell script within a SQL job.

    ServerName InstanceName IsClustered Version

    ---------- ------------ ----------- -------

    ABCDEFGHI No 10.0.4000.0

    ABCDEFGHI MSSQLSERVER2012 No 11.0.3000.0

    SFVSDVSDV No 11.0.5058.0

    HDDBHDGHH No 10.50.1600.1

    But I want my text extract to only look like this without any column header or in a delimited format (pipe / tab)

    ABCDEFGHI

    ABCDEFGHI

    SFVSDVSDV

    HDDBHDGHH

    Thanks

  • There's a bunch of ways to do this using T-SQL, a CLR, Powershell, cmdexec, etc. You should copy an attachment of what the text file looks like (you don't need real info in there) and upload it here. Explain what you want the text file to look like. I'm sure you'll get an answer.

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • Using only Powershell you can do this:

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

    MCITP SQL 2005, MCSA SQL 2012

Viewing 3 posts - 1 through 2 (of 2 total)

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