PowerShell: The Admin Development Model, Win32_NetworkLoginProfile, and DateTime objects

While scanning the PowerShell forums this evening I ran accross this question.  Cruisader03 had already answered the question. The solution.. just…. looked too complicated.  After three years of using PowerShell everyday as my primary means of administration… I offer this simple mantra.

 If it looks complex your doing it wrong!… And you’re the second person to read it. 

I just made that up, but I like it!  Seriously though, this is something I’ve started to notice in my own code.  I believe it is an interesting side effect of the Admin Development Model.  

We cut and paste, one line at a time. Until we get it to work.  By the time we finish a script we know that code not as a script, but as a series of lines. (Pay attention, I bet you still read it like a series of one liners).  In that context it looks fine, but wait 24hr’s and look again… not the same is it.   Now that you’re looking at a finished script.   You will start to find all sorts of inefficiencies and poor grammar usage.   So you polish it up a little… rinse and repeat 100 times, and post to PoshCode!  So goes the Admin Development Model.  With that in mind I offer this simple snip it, more a refactor of  Cruisader03 post than a solution.

~Glenn

3 thoughts on “PowerShell: The Admin Development Model, Win32_NetworkLoginProfile, and DateTime objects”

  1. Great post but I can’t get the script to work, and not sure why. The error response line number would indicate it’s this line:
    LogonTime=[datetime]::ParseExact($CorrectedDTG, “yyyyMMddhhmmss.ffffffzz”, $null)

    Exception calling “ParseExact” with “3” argument(s): “String was not recognized as a valid DateTime.”
    At line:15 char:45
    + LogonTime=[datetime]::ParseExact <<<< ($CorrectedDTG, "yyyyMMddhhmmss.ffffffzz", $null)
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

  2. JKavanagh58, Your system is returning a dtg format that my parser doesn’t understand. I would suggest looking at the raw dtg, and go from there.

    Sorry, I couldn’t be more help, but this is the problem with text. It is just too unpredictable to get 100%.

    ~Glenn

Leave a Reply