question

Mark 1 avatar image
Mark 1 asked

Powershell Register Servers - How do I add a connection property?

I have a little PS script that Buck Wooody posted a while back. I use it to generate a refreshed list of registered servers in a given server group. I would like to add the Custom Color property to the script but haven't been able to find it anywhere. Any help would be appreciated.

This is the script:

cd 'SQLSERVER:\sqlregistration\Database Engine Server Group'

rm group_name -recurse

new-item group_name

cd group_name

new-item SERVERNAME -itemtype registration -Value "server=SERVERNAME;integrated security=true"
..........
sql-serverpowershellprogramming
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Jorge Segarra avatar image
Jorge Segarra answered

Answering separately since this is a complete other solution but you can install SSMS Tools pack (its free) and get that same functionality without having to code at all.

http://ssmstoolspack.com

10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Jorge Segarra avatar image
Jorge Segarra answered

I'm trying to find the recording for the webcast where Buck demonstrates this. Here's one I've found so far (will edit with more links later)

https://msevents.microsoft.com/cui/WebCastEventDetails.aspx?EventID=1032391436&EventCategory=5&culture=en-US&CountryCode=US

Here's the script you were looking for:

http://blogs.msdn.com/buckwoody/archive/2009/10/14/color-your-connections.aspx

10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Tim Benninghoff avatar image
Tim Benninghoff answered

I found this same code on Bob Beauchemin's blog.

Anyway, since you're creating a registration item, you should be able to get your new registration as an object immediately after you create it:

$srv = get-item SERVERNAME;

Once you have this object, you can then theoretically use it's methods to change it's properties through SMO:

$srv.set_UseCustomConnectionColor($True); $srv.set_CustomConnectionColorArgb(-16711936);

--I took the values for these functions from an existing registration I made in SSMS. The ColorArgb is supposed to be green.

However, Bob's note at the bottom of his blog post about the changes made in PowerShell not showing up immediately in SSMS seem to be the case whenever I test. In fact, I can never seem to get the changes to show up in SSMS...ever.

I'm happy to be proven wrong, but my guess is that the new-item cmdlet doesn't quite make the Registration properly enough that you can modify it's properties through SMO.

10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.