Run A query on Multiple servers using CMS

  • 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.

  • 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

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply