Humble beginnings: DNS Resolving for a list of host names

August 6, 2011 2 comments

Here’s my first small Powershell script to share. Tackling DNS cleanup and reorganization over multiple locations and DNS servers, one of my first tasks was to get a reference list of host names and IP Adresses for about twenty domains hosted by us. While ping or nslookup seemed still feasible to use, I anyhow decided to let a script do the tedious work. It takes just a few lines…

 # resolve-all.ps1
# (c) Marcus Schommler, 2011
# Reads in all lines of the specified file and tries DNS name resolution on every line.
# (Apparently the file should contain host names).
# The output is done with Write-Host in a 'XML-snippets' format for reuse
# in another script/project (testing DNS resolutions for multiple DNS servers and multiple host names).

$entries = Get-Content www-all-zones.txt
foreach ($e in $entries) {
   $ips = [System.Net.Dns]::GetHostAddresses($e)
   # A host can have multiple IP adresses, so we iterate over the result of GetHostAddresses():
   foreach ($ip in $ips) {
      # XML-snipped style output for reuse in another project (mass testing of DNS resolutions):
      Write-Host '<dns_test host="'$e'" ip="'$ip'"/>'
   }
}
Advertisements
Categories: powershell Tags: , , ,

Powershell: the powerful beast

August 6, 2011 Leave a comment

With about 30 years of programming experience (I started at age 15 on a programmable calculator, the TI-58C) I’ve tried a lot of programming languages in my time. The latest one I began to use was Powershell. Originating from Microsoft and being pushed by this company as the main supported base for some important business/server products (e.g. Exchange), this was something to look into for my day-to-day IT-administrative needs in the office.  With that decision began what you could call a love/hate relationship – if taking a more professional or detached approach wouldn’t forbid such a strong choice of words.

While this programming language is powerful and flexible in its use, its basic syntax and some of its idiosyncratic concepts are so strange that I started to wonder if the design team tried to outperform Perl in unreadibility and C++ in obscurity of ‘wording’. And yes, I do have coding experience with both of the latter languages.

But even with these points of personal dislike in the background I recently find myself coming back to Powershell more often. Currently it is my premier choice when trying to automate tasks in the area of Microsoft-based IT systems management and consolidation. Powerful, flexible and free is hard to beat, even if you have to accept some ugly warts in return.

Just moved in…

August 6, 2011 Leave a comment

Well, not much here for the moment. I just recently decided to enter the blogging world. My posts will mostly relate to my work as an IT professional and computer programmer. From time to time I might add posts of other things catching my eye – or mind.

Categories: welcome