SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


2008 Central Management Server - Schedule Multi Server Query?


2008 Central Management Server - Schedule Multi Server Query?

Author
Message
cpyne
cpyne
SSC Journeyman
SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)

Group: General Forum Members
Points: 78 Visits: 249
Hi Everyone - I have a 2008 Central Management Server that we're able to run queries from against all our SQL servers. I'm wondering if there's a way to do this via the command line or a job so the queries can be automated and rolled up into reporting services reports. Any suggestions?



simon.letts
simon.letts
Right there with Babe
Right there with Babe (793 reputation)Right there with Babe (793 reputation)Right there with Babe (793 reputation)Right there with Babe (793 reputation)Right there with Babe (793 reputation)Right there with Babe (793 reputation)Right there with Babe (793 reputation)Right there with Babe (793 reputation)

Group: General Forum Members
Points: 793 Visits: 606
Think you may have to do this using the master\target option of a job.
MysteryJimbo
MysteryJimbo
SSCertifiable
SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)

Group: General Forum Members
Points: 5299 Visits: 15346
There's no way of doing it through management studio.

I accomplished this by using powershell and combining multiple resultset along with @@SERVERNAME into a $variable and pinging a HTML email report with the result.
shew
shew
SSCrazy
SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)

Group: General Forum Members
Points: 2584 Visits: 954
MysteryJimbo (10/11/2010)
There's no way of doing it through management studio.

I accomplished this by using powershell and combining multiple resultset along with @@SERVERNAME into a $variable and pinging a HTML email report with the result.


This sounds like exactly what I need to do. Can you post some code?



PHXHoward
PHXHoward
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1837 Visits: 1264
Hi shew and others.

Did you find a way to schedule multi-server queries using PowerShell? I would like to do this too and have been looking at a way to have Enterprise Policy Management Framework use queries in addition to policies.

Howard

shew (11/24/2010)
MysteryJimbo (10/11/2010)
There's no way of doing it through management studio.

I accomplished this by using powershell and combining multiple resultset along with @@SERVERNAME into a $variable and pinging a HTML email report with the result.


This sounds like exactly what I need to do. Can you post some code?

shew
shew
SSCrazy
SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)

Group: General Forum Members
Points: 2584 Visits: 954
No, I haven't. Theoretically, you should be able to load the server names into an array and bump through each element in the array with a sqlcmd.exe statement, but I haven't tried it. This would *not* put all of the result sets into a single stream, but it would allow you to run the same statement on all servers from a single command line.

A while back, I did something similar by hardcoding all of the server names in a PowerShell script that accepts the name of a .sql script as a parameter. It's not perfect, but it allows me to execute desired code with a single call. I just have to remember to update the script to add new servers when the environment changes.



PHXHoward
PHXHoward
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1837 Visits: 1264
This blog article shows how to script multi server queries through PowerShell that can be scheduled as a SQL Agent job. Unfortunately, outputing to the PowerShell window is not useful for something that is automated. I'd like to write the output to a table on my CMS. Enquired as to how that can be done in another thread.

http://blogs.msdn.com/b/sethus/archive/2009/04/09/execute-a-query-on-servers-in-central-management-server-group.aspx
shew
shew
SSCrazy
SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)

Group: General Forum Members
Points: 2584 Visits: 954
PHXHoward (12/20/2010)
This blog article shows how to script multi server queries through PowerShell that can be scheduled as a SQL Agent job. Unfortunately, outputing to the PowerShell window is not useful for something that is automated. I'd like to write the output to a table on my CMS. Enquired as to how that can be done in another thread.

http://blogs.msdn.com/b/sethus/archive/2009/04/09/execute-a-query-on-servers-in-central-management-server-group.aspx



Hmmm... Interesting idea. I need to check this out.

>>Unfortunately, outputing to the PowerShell window is not useful for something that is automated.

sqlcmd.exe and the -o switch can help you get around this limitation of invoke-sqlcmd.

Alternatively, this may help too:

invoke-sqlcmd -ServerInstance $DatabaseConnection_STR -Database dba -Query "select select serverproperty('InstanceName')" -Verbose



muhammadrazzaqpk-1032285
muhammadrazzaqpk-1032285
SSC Rookie
SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)

Group: General Forum Members
Points: 37 Visits: 131
Can someone Please post the code for scheduling a job on Central management server? I am desperately looking for the code.
PHXHoward
PHXHoward
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1837 Visits: 1264
muhammadrazzaqpk-1032285 (12/5/2011)
Can someone Please post the code for scheduling a job on Central management server? I am desperately looking for the code.


You can create a SQL Agent Powershell job likethis:


$instanceNameList = invoke-Sqlcmd -query "
SELECT [server_name] as Name
FROM [msdb].[dbo].[sysmanagement_shared_registered_servers_internal] SSRSI
join [msdb].[dbo].[sysmanagement_shared_server_groups_internal] SSSGI
on SSRSI.server_group_id = SSSGI.server_group_id
where SSSGI.parent_id = '<use this if you want to limit the included servers to a CMS group>'
" -serverinstance "<your CMS here>"
$results = @()

foreach($instanceName in $instanceNameList)
{$results += Invoke-Sqlcmd -Query "

<your query here>

" -ServerInstance $instanceName.Name}

$results| Where-Object {$_} | Export-Csv <path to save csv file> -NoTypeInformation


It will dump the query results to a text file that can be loaded into your CMS using an SSIS step. Pretty powerful so I suggest that you run the Agent job with a proxy account that only has read access to the servers in the CMS.

The above example has four places that must be changed to replace the <...>

Hope that helps

Howard
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search