{"id":6391,"date":"2008-04-11T11:58:33","date_gmt":"2008-04-11T11:58:33","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2008\/04\/11\/managing-datacenter-machine-names\/"},"modified":"2019-02-18T13:16:03","modified_gmt":"2019-02-18T20:16:03","slug":"managing-datacenter-machine-names","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/managing-datacenter-machine-names\/","title":{"rendered":"Managing Datacenter Machine Names"},"content":{"rendered":"<p>One of the first things managers of large scale datacenter do is to produce a regular naming scheme for their servers.&#160; These often embed the function, location, and then an integer.&#160; e.g.<\/p>\n<p>&#160;<\/p>\n<p> IIS-West-001  <br \/>IIS-West-002  <br \/>&#8230;  <br \/>IIS-West-234  <\/p>\n<p>or <\/p>\n<p> ShareP-Tuk-001  <br \/>ShareP-Tuk-002    <\/p>\n<p>&#8230;   <br \/>ShareP-Tuk-010    <\/p>\n<p>PowerShell&#8217;s range operator is awesome for working with these environments.&#160; If you haven&#8217;t already discovered it, the Range Operator is .. &#8211; it takes any 2 integers and generates all the numbers between them (including them).&#160; An example is worth a thousand words:<\/p>\n<p>PS&gt;1..3   <br \/>1    <br \/>2    <br \/>3    <br \/>PS&gt; # Notice that it can work backwards as well    <br \/>PS&gt;3..1    <br \/>3    <br \/>2    <br \/>1    <br \/>PS&gt; # You can start\/stop anywhere you want    <br \/>PS&gt;33..35    <br \/>33    <br \/>34    <br \/>35<\/p>\n<p>&#160;<\/p>\n<p>So that is ALMOST useful for this environment because you can do things like:<\/p>\n<p>PS&gt;1..5 |%{&quot;IIS-West-{0}&quot; -f $_}   <br \/>IIS-West-1    <br \/>IIS-West-2    <br \/>IIS-West-3    <br \/>IIS-West-4    <br \/>IIS-West-5<\/p>\n<p>Is that cool or what!<\/p>\n<p>Well yes AND no.&#160; Notice that in the original example, the integers where padded with 0s.&#160; Admins do this so that the width of the server names is fixed so it makes it easy to do reporting and have everything line up correctly.&#160; Well .NET formating strings come to the rescue here.&#160; Kathy Kam has a great .Net Format String 101 blog entry with lots of examples <a href=\"http:\/\/blogs.msdn.com\/kathykam\/archive\/2006\/03\/29\/564426.aspx\">HERE<\/a> .&#160; You can zero pad numbers this way:<\/p>\n<p>PS&gt;1..5 |%{&quot;IIS-West-{0:000}&quot; -f $_}   <br \/>IIS-West-001    <br \/>IIS-West-002    <br \/>IIS-West-003    <br \/>IIS-West-004    <br \/>IIS-West-005<\/p>\n<p>Man I love this stuff!<\/p>\n<p>Here is my new motto:&#160; Buy as many Windows Servers as you like, we&#8217;ll make it easy to manage them.&#160; \ud83d\ude42<\/p>\n<p>Enjoy!<\/p>\n<p>Jeffrey Snover [MSFT]   <br \/>Windows Management Partner Architect    <br \/>Visit the Windows PowerShell Team blog at:&#160;&#160;&#160; <a href=\"http:\/\/blogs.msdn.com\/PowerShell\">http:\/\/blogs.msdn.com\/PowerShell<\/a>    <br \/>Visit the Windows PowerShell ScriptCenter at:&#160; <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx\">http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the first things managers of large scale datacenter do is to produce a regular naming scheme for their servers.&#160; These often embed the function, location, and then an integer.&#160; e.g. &#160; IIS-West-001 IIS-West-002 &#8230; IIS-West-234 or ShareP-Tuk-001 ShareP-Tuk-002 &#8230; ShareP-Tuk-010 PowerShell&#8217;s range operator is awesome for working with these environments.&#160; If you haven&#8217;t [&hellip;]<\/p>\n","protected":false},"author":600,"featured_media":13641,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-6391","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell"],"acf":[],"blog_post_summary":"<p>One of the first things managers of large scale datacenter do is to produce a regular naming scheme for their servers.&#160; These often embed the function, location, and then an integer.&#160; e.g. &#160; IIS-West-001 IIS-West-002 &#8230; IIS-West-234 or ShareP-Tuk-001 ShareP-Tuk-002 &#8230; ShareP-Tuk-010 PowerShell&#8217;s range operator is awesome for working with these environments.&#160; If you haven&#8217;t [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/6391","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/users\/600"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/comments?post=6391"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/6391\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media\/13641"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media?parent=6391"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=6391"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=6391"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}