Using PowerShell adding list of servers in CMS in SQL Server

 



$path = get-location

$servers = @(get-content "$path\servers.txt")

{

$q = use [msdb] insert into [dbo].[sysmanagement_shared_registered_servers_internal]

(server_group_id,name,server_name,description,server_type)

values ('45','$server','$server','','0'))"

}

 Invoke-Sqlcmd -serverInstance SQL2019 | -database "master" -query $q


Note: Value 45 is not a default value it may vary according to server group we created in CMS. once we create a group in CMS this will save with on group id, we can see group id in "sysmanagement_shared_server_groups_internal"






Comments

Popular posts from this blog

Capture the deadlocks for review purpose

Migrating SQL Server with minimal downtime from On premise to Azure using DAG (Distributed Availability Group)