Using PowerShell And SSMS Registered Servers


One of the interesting things about the PowerShell provider for SQL Server is that it is integrated so well into the entire environment.

As a case-in-point, you can use the PowerShell provider for SQL Server 2008 to read the registered servers in SQL Server Management Studio (SSMS) and then run a command against them. Here's how I do that:

dir "Database Engine Server Group" | % { invoke-sqlcmd -query "select serverproperty('ServerName') as [Server], serverproperty('ProductVersion') as [Version], serverProperty('ProductLevel') as [Level]" `
-ServerInstance $_.name | ft}


Comments (1)

  1. nikolz says:

    I am getting an error:
    dir : Cannot find path ‘HKEY_LOCAL_MACHINE\Database Engine Server Group’ because it does not exist.
    At line:1 char:1
    + dir “Database Engine Server Group” | % { invoke-sqlcmd -query “select …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ObjectNotFound: (HKEY_LOCAL_MACH…ne Server Group:String) [Get-ChildItem], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

Skip to main content