Click here to monitor SSC
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in
Home       Members    Calendar    Who's On

Add to briefcase

Run A query on Multiple servers using CMS Expand / Collapse
Posted Saturday, December 29, 2012 4:55 PM


Group: General Forum Members
Last Login: Wednesday, December 16, 2015 9:58 AM
Points: 19, Visits: 122
Hi ,

I want to run a query on Multiple servers i am using CMS to run it on multiple on server.
Now i want to automate this through job,powershell,sqlcmd ...and the result should export to CSV.
Pls help.
Post #1401212
Posted Monday, December 31, 2012 12:10 PM



Group: General Forum Members
Last Login: Today @ 3:25 AM
Points: 7,933, Visits: 14,355
Those requirements are a bit vague. Are you running a select statement? An update? What will your CSV look like?

Here is some boilerplate PowerShell code to help you get you started interacting with your CMS.

$serverGroupPath = 'SQLSERVER:\SQLRegistration\Central Management Server Group\<GroupName>\'
$instanceNameList = dir $serverGroupPath -recurse | where-object { $_.Mode.Equals("-") } | select-object Name -Unique

foreach($instanceName in $instanceNameList)
# do something against each server here

There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Post #1401472
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse