Managing Datacenter Machine Names

Managing Datacenter Machine Names

  • Comments 6

One of the first things managers of large scale datacenter do is to produce a regular naming scheme for their servers.  These often embed the function, location, and then an integer.  e.g.

 

IIS-West-001
IIS-West-002
...
IIS-West-234

or

ShareP-Tuk-001
ShareP-Tuk-002

...
ShareP-Tuk-010

PowerShell's range operator is awesome for working with these environments.  If you haven't already discovered it, the Range Operator is .. - it takes any 2 integers and generates all the numbers between them (including them).  An example is worth a thousand words:

PS>1..3
1
2
3
PS> # Notice that it can work backwards as well
PS>3..1
3
2
1
PS> # You can start/stop anywhere you want
PS>33..35
33
34
35

 

So that is ALMOST useful for this environment because you can do things like:

PS>1..5 |%{"IIS-West-{0}" -f $_}
IIS-West-1
IIS-West-2
IIS-West-3
IIS-West-4
IIS-West-5

Is that cool or what!

Well yes AND no.  Notice that in the original example, the integers where padded with 0s.  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.  Well .NET formating strings come to the rescue here.  Kathy Kam has a great .Net Format String 101 blog entry with lots of examples HERE .  You can zero pad numbers this way:

PS>1..5 |%{"IIS-West-{0:000}" -f $_}
IIS-West-001
IIS-West-002
IIS-West-003
IIS-West-004
IIS-West-005

Man I love this stuff!

Here is my new motto:  Buy as many Windows Servers as you like, we'll make it easy to manage them.  :-)

Enjoy!

Jeffrey Snover [MSFT]
Windows Management Partner Architect
Visit the Windows PowerShell Team blog at:    http://blogs.msdn.com/PowerShell
Visit the Windows PowerShell ScriptCenter at:  http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx

Leave a Comment
  • Please add 7 and 5 and type the answer here:
  • Post
  • ---"Buy as many Windows Servers as you like, we'll make it easy to manage them."

    Just as long as they are virtual Servers right Jeffrey :) Got too keep it green

    hehehe

    Chris

  • PS C:\Users\daniel.hofmann> 1..50000 |%{"IIS-West-{0:000}" -f $_} >c:\test.txt

    PS C:\Users\daniel.hofmann> 1..50000 |%{"IIS-West-{0:00000}" -f $_} >c:\test.txt

    PS C:\Users\daniel.hofmann> 1..5000000 |%{"IIS-West-{0:0000000}" -f $_} >c:\test.txt

    Bad range expression; 4999999 is larger than the maximum size of a range (=50000 elements).

  • > PS C:\Users\daniel.hofmann> 1..5000000 |%{"IIS-West-{0:0000000}" -f $_} >c:\test.txt

    > Bad range expression; 4999999 is larger than the maximum size of a range (=50000 elements).

    If you promise to buy that many Windows Servers, I'll promise to fix that bug.

    Deal?

    (Actually, we've already fixed in V2 so you better start buying those servers. :-) )

    Jeffrey Snover [MSFT]

    Windows Management Partner Architect

    Visit the Windows PowerShell Team blog at:    http://blogs.msdn.com/PowerShell

    Visit the Windows PowerShell ScriptCenter at:  http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx

  • Remember that you can easily construct a range with "holes". Let's for instance say that your servers are numbered from 1-15 and from 50-60:

    (1..15 + 50..60) |%{"IIS-West-{0:000}" -f $_}

  • Don't forget the network configuration.  Once you've got all those servers named, you'll have to deploy them and if you are lucky enough to be using a BIG-IP to front all your servers, you can use the iControl Cmdlets to provision all those servers at the network layer.

    iControl PowerShell Cmdlets: http://devcentral.f5.com/Default.aspx?tabid=71

  • creates sequential directories

    1..100 | %{ni ( "NewDirectory-{0:0}" -f $_ ) -type directory }

    creates files with sequential content

    1..100 | %{ni ( "NewFile-{0:0}" -f $_ ) -type "file" -value "Number $_ of 100 files."}

Page 1 of 1 (6 items)