Skip to content Skip to sidebar Skip to footer

Adding Servers To Sql Management Studio

I would like to add a bunch of SQL (mixture of 2000-2005) server instances on different servers to my SSMS (SQL Managment Studio) Registered servers, I was following this tutorial

Solution 1:

If you save the Excel spreadsheet as a CSV file, you can easily import it in PowerShell using the Import-Csv cmdlet and automatically register the servers in the list by their names.

Assuming your CSV file looks like this:

|Name    |
|Server1 |
|Server2 |
|Server3 |

The following command will import its content as a list of objects, one for each row in the CSV file, all having a Name property, which contains the actual value. Those names are then used within the string passed to the New-Item cmdlet to actually do the registration:

Import-Csv ServersToRegister.csv | ForEach-Object { `
    New-Item $(Encode-Sqlname $_.Name) -ItemType Registration `
        -Value ("server=$($_.Name);integrated security=true") }

You can specify the username and password to use to connect to the SQL Server instance by passing a PSCredential object to the New-Item cmdlet. So the complete command would be:

Import-Csv ServersToRegister.csv | ForEach-Object { `
    New-Item $(Encode-Sqlname $_.Name) -ItemType Registration `
        -Value ("server=$($_.Name);integrated security=true") `
        -Credential (New-Object System.Management.Automation.PSCredential("username", "password")) }

Post a Comment for "Adding Servers To Sql Management Studio"