Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
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: Tuesday, April 08, 2014 8:27 AM
Points: 19, Visits: 112
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: 2 days ago @ 9:25 AM
Points: 7,070, Visits: 12,523
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

Believe you can and you're halfway there. --Theodore Roosevelt

Everything Should Be Made as Simple as Possible, But Not Simpler --Albert Einstein

The significant problems we face cannot be solved at the same level of thinking we were at when we created them. --Albert Einstein

1 apple is not exactly 1/8 of 8 apples. Because there are no absolutely identical apples. --Giordy
Post #1401472
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse