{"id":685,"date":"2008-07-08T07:23:00","date_gmt":"2008-07-08T07:23:00","guid":{"rendered":"\/blogs\/bobb\/post\/Programming-SQLRegistration-in-the-SQL-Server-PowerShell-Provider.aspx"},"modified":"2008-07-08T07:23:00","modified_gmt":"2008-07-08T07:23:00","slug":"programming-sqlregistration-in-the-sql-server-powershell-provider","status":"publish","type":"post","link":"https:\/\/www.sqlskills.com\/blogs\/bobb\/programming-sqlregistration-in-the-sql-server-powershell-provider\/","title":{"rendered":"Programming SQLRegistration in the SQL Server PowerShell Provider"},"content":{"rendered":"<p>\nI&#39;ve noticed that some folks have written PowerShell scripts that execute against a list of servers. In the scripts, they read the names of the servers from XML files. But the SQL Server PowerShell provider in RC0&nbsp;has a useful &quot;component&quot; called SQLRegistration; its &quot;path&quot; is SQLSERVER:\\SQLRegistration that they can use instead.\n<\/p>\n<p>\nThis path permits enumeration and manipulation&nbsp;of&nbsp;the (SQL) servers and server groups that are defined using SQL Server Management Studio. The SQLRegistration path is not specific to server or instance, but to the SSMS user that&#39;s signed on. For example, on the same physical machine, SQLRegistration for the Windows user bobb reflects bobb&#39;s settings in SSMS. SQLRegistration for user mary (on the same machine) would reflect mary&#39;s SSMS settings. There is no SQLSERVER:\\SQLRegistration\\{machinename}\\{instancename} path, just SQLSERVER:\\SQLRegistration.\n<\/p>\n<p>\nSQLRegistration contains two &quot;subdirectories&quot;, called &quot;Central Management Server Group&quot; and &quot;Database Engine Server Group&quot;. These are equivalent to SSMS&#39; &quot;Central Management Servers&quot; and &quot;Local Server Groups&quot; folders, respectively.\n<\/p>\n<p>\nSo rather than write custom XML files that hold information about groups of servers you can use the built-in Registration store. You can import and export registration information to keep team members&#39; view of SQL Servers and groups consistant using SSMS.\n<\/p>\n<p>\nBecause I&#39;ve been writing PowerShell scripts against the provider&#39;s Policy and DataCollection stores, I thought it would be fun to program SQLRegistration. I found the Microsoft.SqlServer.Management.Registration namespace in BOL&nbsp;(which is RC0 is really called Microsoft.SqlServer.Management.Smo.Registration, BOL says this will change before RTM) and was about to code against the RegisteredServer and ServerGroup classes, when I realized that Registration was a simple hierarchies of servers and groups. Just like directories and files. And the built-in groups each have a &quot;mode&quot; property that&#39;s value is &quot;d&quot;. Registered Servers have a blank mode property. Hmmm&#8230;\n<\/p>\n<p>\nSo, at the PowerShell prompt <br \/>\n&gt; cd &#39;SQLSERVER:\\sqlregistration\\Database Engine Server Group&#39;<br \/>\n&gt; new-item MyNewGroup\n<\/p>\n<p>\ncreates a new directory (ServerGroup) named MyNewGroup. Well then,&nbsp;a registered server should be a file.\n<\/p>\n<p>\n&gt; new-item MyNewServer -itemtype file\n<\/p>\n<p>\nNew-Item : SQL Server PowerShell provider error: This provider only supports the<br \/>\ncreation of new Server Groups or Server Registrations. Please specify &quot;directory&quot;<br \/>\nto create a new Server Group or &quot;registration&quot; to create a new Server Registration.\n<\/p>\n<p>\nSo this should work?\n<\/p>\n<p>\n&gt; new-item MyNewServer -itemtype registration\n<\/p>\n<p>\nNew-Item : SQL Server PowerShell provider error: Please specify a connection string using the -Value parameter.\n<\/p>\n<p>\n&gt; new-item MyNewServer -itemtype registration -Value &quot;server=mynewserver;integrated security=true&quot;<br \/>\n&gt;\n<\/p>\n<p>\nYep. This creates a new server registration using the connection parameters that you specify. How cool is that? No other part of the SQL SERVER PowerShell provider that I&#39;m aware of supports the new-item cmdlet\/operation. Because the SQLRegistration represent fairly simple items and hierarchies new-item is supported here. No custom programming needed (although you can use the SMO classes if you&#39;d rather), just treat it as you would file system.\n<\/p>\n<p>\nA couple of caveats. In RC0 SSMS and PowerShell SQLRegisgtration sync up when you open SSMS but if you&#39;re using both at once, the sync to SSMS isn&#39;t immediate. Sometimes refresh doesn&#39;t appear to show the changes you made in PowerShell. Eventually it will show them if you refresh multiple times&nbsp;or restart SSMS.&nbsp;And after deleting a Server Registration in SSMS, I still had to run &quot;rm MyNewServer&quot; in PowerShell to get rid of it there. Also, I use &quot;integrated security=sspi&quot; rather than &quot;integrated security=true&quot; in my ADO.NET connection strings. This seems to bother SSMS which reports an error in configuration. Use &quot;true&quot; rather than &quot;sspi&quot; when creating registrations through PowerShell.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#39;ve noticed that some folks have written PowerShell scripts that execute against a list of servers. In the scripts, they read the names of the servers from XML files. But the SQL Server PowerShell provider in RC0&nbsp;has a useful &quot;component&quot; called SQLRegistration; its &quot;path&quot; is SQLSERVER:\\SQLRegistration that they can use instead. This path permits enumeration [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21,29],"tags":[],"class_list":["post-685","post","type-post","status-publish","format-standard","hentry","category-powershell","category-sql-server-2008"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.9.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Programming SQLRegistration in the SQL Server PowerShell Provider - Bob Beauchemin<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.sqlskills.com\/blogs\/bobb\/programming-sqlregistration-in-the-sql-server-powershell-provider\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Programming SQLRegistration in the SQL Server PowerShell Provider - Bob Beauchemin\" \/>\n<meta property=\"og:description\" content=\"I&#039;ve noticed that some folks have written PowerShell scripts that execute against a list of servers. In the scripts, they read the names of the servers from XML files. But the SQL Server PowerShell provider in RC0&nbsp;has a useful &quot;component&quot; called SQLRegistration; its &quot;path&quot; is SQLSERVER:SQLRegistration that they can use instead. This path permits enumeration [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlskills.com\/blogs\/bobb\/programming-sqlregistration-in-the-sql-server-powershell-provider\/\" \/>\n<meta property=\"og:site_name\" content=\"Bob Beauchemin\" \/>\n<meta property=\"article:published_time\" content=\"2008-07-08T07:23:00+00:00\" \/>\n<meta name=\"author\" content=\"Bob Beauchemin\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Bob Beauchemin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/programming-sqlregistration-in-the-sql-server-powershell-provider\/\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/programming-sqlregistration-in-the-sql-server-powershell-provider\/\",\"name\":\"Programming SQLRegistration in the SQL Server PowerShell Provider - Bob Beauchemin\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website\"},\"datePublished\":\"2008-07-08T07:23:00+00:00\",\"dateModified\":\"2008-07-08T07:23:00+00:00\",\"author\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/programming-sqlregistration-in-the-sql-server-powershell-provider\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqlskills.com\/blogs\/bobb\/programming-sqlregistration-in-the-sql-server-powershell-provider\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/programming-sqlregistration-in-the-sql-server-powershell-provider\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PowerShell\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/category\/powershell\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Programming SQLRegistration in the SQL Server PowerShell Provider\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/\",\"name\":\"Bob Beauchemin\",\"description\":\"SQL Server Blog\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e\",\"name\":\"Bob Beauchemin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g\",\"caption\":\"Bob Beauchemin\"},\"sameAs\":[\"http:\/www.sqlskills.com\/blogs\/bobb\/\"],\"url\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/author\/bobb\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Programming SQLRegistration in the SQL Server PowerShell Provider - Bob Beauchemin","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.sqlskills.com\/blogs\/bobb\/programming-sqlregistration-in-the-sql-server-powershell-provider\/","og_locale":"en_US","og_type":"article","og_title":"Programming SQLRegistration in the SQL Server PowerShell Provider - Bob Beauchemin","og_description":"I&#39;ve noticed that some folks have written PowerShell scripts that execute against a list of servers. In the scripts, they read the names of the servers from XML files. But the SQL Server PowerShell provider in RC0&nbsp;has a useful &quot;component&quot; called SQLRegistration; its &quot;path&quot; is SQLSERVER:SQLRegistration that they can use instead. This path permits enumeration [&hellip;]","og_url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/programming-sqlregistration-in-the-sql-server-powershell-provider\/","og_site_name":"Bob Beauchemin","article_published_time":"2008-07-08T07:23:00+00:00","author":"Bob Beauchemin","twitter_misc":{"Written by":"Bob Beauchemin","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/programming-sqlregistration-in-the-sql-server-powershell-provider\/","url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/programming-sqlregistration-in-the-sql-server-powershell-provider\/","name":"Programming SQLRegistration in the SQL Server PowerShell Provider - Bob Beauchemin","isPartOf":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website"},"datePublished":"2008-07-08T07:23:00+00:00","dateModified":"2008-07-08T07:23:00+00:00","author":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e"},"breadcrumb":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/programming-sqlregistration-in-the-sql-server-powershell-provider\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlskills.com\/blogs\/bobb\/programming-sqlregistration-in-the-sql-server-powershell-provider\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/programming-sqlregistration-in-the-sql-server-powershell-provider\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlskills.com\/blogs\/bobb\/"},{"@type":"ListItem","position":2,"name":"PowerShell","item":"https:\/\/www.sqlskills.com\/blogs\/bobb\/category\/powershell\/"},{"@type":"ListItem","position":3,"name":"Programming SQLRegistration in the SQL Server PowerShell Provider"}]},{"@type":"WebSite","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website","url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/","name":"Bob Beauchemin","description":"SQL Server Blog","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqlskills.com\/blogs\/bobb\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e","name":"Bob Beauchemin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g","caption":"Bob Beauchemin"},"sameAs":["http:\/www.sqlskills.com\/blogs\/bobb\/"],"url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/author\/bobb\/"}]}},"_links":{"self":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/posts\/685","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/comments?post=685"}],"version-history":[{"count":0,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/posts\/685\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/media?parent=685"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/categories?post=685"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/tags?post=685"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}