November 12, 2015 at 12:31 pm
I'm using PowerShell as well but not with the CMS. How does that work? I'd be appreciative of that information and a copy of your script if you don't mind. Thanks, Marcus.
November 12, 2015 at 12:42 pm
mhorner 67968 (11/12/2015)
I'm using PowerShell as well but not with the CMS. How does that work? I'd be appreciative of that information and a copy of your script if you don't mind. Thanks, Marcus.
you can query the msdb database, of the server that serves up the Central Management Server list.
with that list, you can use powershell to connect to each one;
select * from msdb.dbo.sysmanagement_shared_server_groups_internal
select * from msdb.dbo.sysmanagement_shared_registered_servers_internal
select * from msdb.dbo.sysmanagement_shared_registered_servers
select * from msdb.dbo.sysmanagement_shared_server_groups
here's an example where i pull stuff together:
SELECT ROW_NUMBER()
OVER (
PARTITION BY TheServer.NAME
ORDER BY TheServer.NAME) AS rw,
TheGroup.NAME AS [servergroup],
TheGroup.[Description] AS [groupdescription],
TheServer.NAME,
TheServer.server_name AS [servername],
TheServer.[description] AS [description]
FROM [HOL-WKS-444].msdb.dbo.sysmanagement_shared_server_groups_internal TheGroup
LEFT JOIN [HOL-WKS-444].msdb.dbo.sysmanagement_shared_registered_servers_internal TheServer
ON TheGroup.server_group_id = TheServer.server_group_id
WHERE TheGroup.server_type = 0 --only the Database Engine Server Group
AND server_name IS NOT NULL
Lowell
November 12, 2015 at 1:30 pm
Thank you very much. Works well.
September 15, 2016 at 9:07 am
Hello,
Can you send my your example script (Powershell) per private message?
Thx!
Lello
January 3, 2020 at 3:11 pm
How can it be done using powershell?
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "integrated security=SSPI; data source=?????; initial catalog=??????;"
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = "dba.dbo.stp_get_version"
$SqlCmd.Connection = $SqlConnection
$SqlCmd.CommandType = [System.Data.CommandType]::StoredProcedure
$p1=$SqlCmd.Parameters.Add("@htmloutput", "")
$p1.Direction = [system.Data.ParameterDirection]::Output
$p1.Size=8000
$SqlConnection.Open()
$SqlCmd.ExecuteNonQuery()
$p1.SqlValue.Value
$MsgBody = $p1.SqlValue.Value
$SMTPSvr = 'my_exchange_server'
$from = 'me@mail.com'
$recipients = "you@mail.com, you2@mail.com"
[string[]]$to = $recipients.Split(',')
Send-MailMessage –From $from –To $to –Subject “server versions” -Body $MsgBody -SmtpServer $SMTPSvr -BodyAsHTML
Viewing 5 posts - 16 through 19 (of 19 total)
You must be logged in to reply to this topic. Login to reply