My digital notepad RSS 2.0
 Thursday, January 11, 2007

Our primary DNS server changed it's IP yesterday and we had a secondary DNS server with several domains that needed to have the IP for the master server updated. Windows' gift and curse is that you don't have a bunch of text files where you can find everything but manually opening the properties of every domain, removing the previous master IP, adding a new IP and moving on to the next domain was just not an option.

That's why we have Windows Management Instrumentation (WMI). For an administrator it's the best thing that's happened since they started slicing bread. Well, not quite, but if you intend to do some serious administration of Windows servers you'd better look into it. If you don't like looking through a bunch of documentation for figure out what to do, use Scriptomatic 2.0 like I did yesterday. It will generate a basic script for you that can easily be modified.

Now, the main event: a script to update the master server IP for all secondary DNS zones on a Windows computer.

  1. ' This script updates the Master server IP for all secondary zones on the
  2. ' specifed computers.
  3.  
  4. ' Constants for WMI
  5. Const wbemFlagReturnWhenComplete = &H0
  6. Const wbemFlagReturnImmediately = &h10
  7. Const wbemFlagForwardOnly = &h20
  8. Const iDnsSecondary = 2
  9.  
  10.  
  11. ' The array to hold the master servers
  12. ' (there can be multiple master servers)
  13. Dim MasterServersArray(0)
  14. ' Add the master servers to the array. Replace with your own IP
  15. MasterServersArray(0) = "192.168.2.10"
  16.  
  17. ' The address of the old master server, replace with your own IP
  18. ' Used to check the zone and only update those that need it.
  19. Dim strOldMasterServer
  20. strOldMasterServer = "10.0.0.10"
  21. ' The script can do this on multiple computers,
  22. ' just add them to the array
  23. Dim arrComputers
  24. arrComputers = Array("COMPUTERNAME")
  25.  
  26. Dim objWMIService
  27. Dim colItems
  28. Dim objItem
  29.  
  30. For Each strComputer In arrComputers
  31.         WScript.Echo
  32.         WScript.Echo "=========================================="
  33.         WScript.Echo "Computer: " & strComputer
  34.         WScript.Echo "=========================================="
  35.        
  36.         WScript.Echo "Fetching zones..."
  37.         ' Connect to the DNS WMI interface on the current computer
  38.         Set objWMIService = GetObject("winmgmts:\\" & strComputer _
  39.                 & "\root\MicrosoftDNS")
  40.  
  41.         ' Get all zones from the DNS server. We use wbemFlagReturnWhenComplete
  42.         ' to make sure the call completes before returning. If not we often get
  43.         ' errors when looping through the returned collection. If you only want 
  44.         ' some zones to be updated you can filter your query just like any SQL query.
  45.         Set colItems = objWMIService.ExecQuery("SELECT * FROM MicrosoftDNS_Zone", _
  46.                 "WQL", wbemFlagReturnWhenComplete + wbemFlagForwardOnly)
  47.         WScript.Echo "Retrieved zones."
  48.  
  49.         ' Used to hold a return object.
  50.         dim objTmp
  51.  
  52.         For Each objItem In colItems
  53.           ' Only secondary zones have master servers
  54.           if objItem.ZoneType = iDnsSecondary then     
  55.                 ' Get the current master IPs 
  56.                         strMastersIPAddressesArray = Join(objItem.MastersIPAddressesArray, ",")
  57.                        
  58.                         ' Some information
  59.                         WScript.Echo "Name: " & objItem.Name
  60.                         WScript.Echo "MastersIPAddressesArray: " & strMastersIPAddressesArray
  61.  
  62.                         ' We'll only do this in the zones with the old master server
  63.                         ' No need to update zones that don't need it.
  64.                         if strMastersIPAddressesArray = strOldMasterServer then
  65.                           ' ResetMasterIpArray is a function on the WMI object
  66.                           ' that replacesthe current array of Master IPs.
  67.                           ' objTemp receives a refrence to the updated zone.
  68.                           objItem.ResetMasterIpArray MasterServersArray, objTemp
  69.                           ' We don't need it so we set it to nothing
  70.                           ' immediatly to save memory
  71.                           set objTemp = nothing
  72.                           WScript.Echo
  73.                         end If
  74.                         ' Let's just make the secondary zone refresh from
  75.                         ' the master server while we're at it
  76.                         objItem.ForceRefreshOfSecondaryZoneFromMaster()
  77.           end if
  78.         Next
  79. Next
UpdateMasterServerIP.vbs (2,82 KB)
 
Thursday, January 11, 2007 9:39:17 AM (Central Europe Standard Time, UTC+01:00)  #    Comments [0] -
Administration | Scripting

This isn't funny unless you're from Norway, but if you are it's absolutely hilarious!!

Last summer four artists got together and sang "Hallelujah" and reaped in the cash, this is a parody of them.

 
Thursday, January 11, 2007 9:34:38 AM (Central Europe Standard Time, UTC+01:00)  #    Comments [0] -
Videos | Funny
 Wednesday, January 10, 2007
But they did. In the movie Cthulhu. Appearantly the movie is done and they are looking for a distributor. Seems like an odd way to do it...

 
Wednesday, January 10, 2007 3:19:27 PM (Central Europe Standard Time, UTC+01:00)  #    Comments [0] -
Movies
 Friday, January 05, 2007

A somewhat akward title, but I had a hard time finding a better one :)

We have a projects folder. In that folder there is one folder for each project and in each project folder there is a documents folder (among many others). Now, I needed to find the size of each documents folder for each project and ignore the other folders (don't ask me why).

Seeing as there are a few hundred projects and each documents folder can contain from five to several thousand files I did not want to check each folder. Since the other folders are even larger, listing the size of everything and take out what I did not need would increase the time to create the listing.

So I created a PowerShell script. Was that the fastest way to do it? Probably not, but I'll have to do this again someday and then I'll save lots of time. Besides, it didn't take all that long to create.

$hashTbl=@{};
Get-ChildItem | where-object {$_.Mode -eq "d----"} | `
 foreach-object  { `
   $_.Name;`
  $hashTbl[$_] = ( get-childitem($_.Name + "\documents")`
-recurse -force| `
   measure-object length -sum )
  };
$output = ($hashTbl.psbase.keys |`
 foreach `
  {"Name,Size,File count"} `
  { $_.Name + "," + $hashTbl[$_].Sum + ","`
+ $hashTbl[$_].Count } `
 );
New-Item c:\temp\DirectorySize.csv -type file -force | out-null;
Add-Content c:\temp\DirectorySize.csv  $output;
import-csv c:\temp\DirectorySize.csv;

Since some might wonder what the heck I'm doing here (like myself, six months from now) I thought I'd go through it line by line.

Instansiate an empty hash table

$hashTbl=@{};

Get a list of all children in the current directory and use where-object to get only the objects that have the directory attibute i.e. just directories and not files.

Get-ChildItem | where-object {$_.Mode -eq "d----"} | `

The result from here is piped into a foreach-object that will do an operation for each object.

 foreach-object  { `

In this operation I display the Name of the folder. This will be outputted while the script is running, giving me feedback on progress. The ; seperates commands.

   $_.Name;`

The next command might need a bit more explaining.

  $hashTbl[$_] = ( get-childitem($_.Name + "\documents")`
-recurse -force| `
   measure-object length -sum )

From the inside and out: First we use get-childitem for the documents folder. $_ is an auto-variable from the foreach and contains the current object in the loop. $_.Name is the name of that folder. Add "\documents" to that to look at the sub-folder I want. -recurse gets the children of all sub folders and -force includes hidden files.

get-childitem($_.Name + "\documents") -recurse -force 

Then we pipe that into measure-object and tells it to sum the length property of all the items returned from get-childitem.

get-childitem($_.Name + "\documents") -recurse -force| `
   measure-object length -sum )

That creates a GenericMeasureInfo object that I put into the hashtable for later.

$hashTbl[$_] = ( get-childitem($_.Name + "\documents")`
-recurse -force| `
   measure-object length -sum )

This loops though all the keys in the hashtable and outputs a string with the values comma-separated. The {"Name,Size,File count"} is the before statement in the foreach that executes before the loop, outputting the headers for my comma-separated list. The ( ) around everything makes it a list that I can save in $output.

$output = ($hashTbl.psbase.keys |`
 foreach `
  {"Name,Size,File count"} `
  { $_.Name + "," + $hashTbl[$_].Sum + ","`
+ $hashTbl[$_].Count } `
 );

Create a new file, overwriting any old file. Output is supressed.

New-Item c:\temp\DirectorySize.csv -type file -force | out-null;

Add the comma-separated list to the file.

Add-Content c:\temp\DirectorySize.csv  $output; 

Read it and display it for information purposes only.

import-csv c:\temp\DirectorySize.csv;

There, all done. Any questions?

subSubDirSize.ps1 (,51 KB)
 
Friday, January 05, 2007 3:00:02 PM (Central Europe Standard Time, UTC+01:00)  #    Comments [3] -
Administration | Powershell | Scripting
 Thursday, January 04, 2007

SightSpeed ScreenshotA friend of mine introduced me to SightSpeed the other day, and I must say I'm impressed! My previous experiences with webcam conversations were "less than optimal" to say the least. Poor image quality, lagging, voice out of sync with video, etc.

With Sightspeed I got excellent video quality (comparable to VHS, which is the best I can do with my camera), the voice was crisp and clear, echo reduction built in, easy set up and easy to call. A small thing, but I was impressed with the speed it connects at. When I double-click a contact it almost instantly connects and rings on the other side.

But don't take my word for it, download a copy and give me a call. Use my personal e-mail to add me as a contact. If you don't have my personal e-mail account, send me an e-mail via the link on the right. It comes in two versions, one free and one with a payment plan that gives you conferencing features. It even comes in a Windows and MacOS version.

I have not tested it properly behind several firewalls so I'm not sure how much effort it is to configure it, but browsing through the support page it looks fairly straight forward.

Web camSo far, I've only got one negative comment. They offer a Click-To-Call button that you can put on your webpage, letting visitors go to a web page where they can install an ActiveX control and start a video call with you without downloading or installing a program. This seems like a good idea, and it probably is too, but on the web page my e-mail address is displayed in plain text. This is a Bad Thing™. Displaying an e-mail address in plain text enables spammers to harvest it and I really don't need more spam. Too-bad, the Click-To-Call button would have fitted nicely in on the right here... 

 
Thursday, January 04, 2007 1:48:12 PM (Central Europe Standard Time, UTC+01:00)  #    Comments [2] -
Communications | Internet
 Wednesday, January 03, 2007

I have a GridView with a BoundField containing a DateTime value, but instead of "01.07.2006 00:00:00" I wanted it to display "June, 2007". Easily fixed with a DataFormatString="{0:MMMM, yyyy}", right? Not so... It refused to apply the format string. Luckily, Google came to the resque again, Raj Kaimal had the same problem and solved it.

Turns out that the field value is HTML encoded before the format string is applied. Add a HtmlEncode="False" to the BoundField and the problem is solved. Thanks Raj!

 
Wednesday, January 03, 2007 11:24:06 PM (Central Europe Standard Time, UTC+01:00)  #    Comments [0] -
ASP.NET | Programming

Eric S. Raymond has an interesting article where he claims that 2008 is a hard deadline for an operating system to become the standard for desktop computing. With 64-bit hardware coming out there is an opening for any OS to become dominant on the new hardware platform and Raymond contends that by 2008 the de facto standard will be set and network effects will do the rest.

Steven Den Beste (fantastic surname :) ) has an interesting view on why Linux won't make it as the dominant desktop platform, comparing it to Christianity in the 17th century.

 
Wednesday, January 03, 2007 7:42:04 PM (Central Europe Standard Time, UTC+01:00)  #    Comments [0] -
Operating Systems
 Tuesday, January 02, 2007

The Opera browser was released for the Wii console a week or two ago and already the adult industry is adapting to the new platfom.

I'll never be able to look at a Wiimote the same way again...

 
Tuesday, January 02, 2007 5:55:42 PM (Central Europe Standard Time, UTC+01:00)  #    Comments [1] -
Internet
 Wednesday, December 20, 2006

This is another reason not to haul a dead tree into the house...


Christmas Tree Goes Up In Flames - video powered by Metacafe

 
Wednesday, December 20, 2006 12:52:21 PM (Central Europe Standard Time, UTC+01:00)  #    Comments [1] -
Videos
 Tuesday, December 19, 2006

Cool coca cola ad:

 
Tuesday, December 19, 2006 10:46:34 AM (Central Europe Standard Time, UTC+01:00)  #    Comments [0] -
Computer games | Funny | Videos
Links
Twitter updates
    Archive
    <January 2007>
    SunMonTueWedThuFriSat
    31123456
    78910111213
    14151617181920
    21222324252627
    28293031123
    45678910
    About the author/Disclaimer

    Disclaimer
    The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

    © Copyright 2012
    Glenn F. Henriksen
    Sign In
    Statistics
    Total Posts: 46
    This Year: 0
    This Month: 0
    This Week: 0
    Comments: 31
    All Content © 2012, Glenn F. Henriksen
    DasBlog theme 'Business' created by Christoph De Baene (delarou)