Get-HotFix and get-WmiObject Win32_QuickFixEngineering missing InstalledOn property

Hello All

When using either of the above,  most of my HotFixes show no InstalledOn or InstalledDate

However when I look in Control Panel > Programs and Features > View Installed Updates

they all show an Installed On date

I want to collect this information from local/remote computers and will therefore use the WMI option in my environment, but I need to retrieve the InstalledOn

If the above has a bug perhaps I need to go looking around in the registry,

any help most appreciated

Thanks

Ernie

Parents
  • I found that InstalledOn is a script paramter defined by the following:

    Get-HotFix | gm -Name installedon | Select-Object -ExpandProperty definition
    System.Object InstalledOn {get=if ([environment]::osversion.version.build -ge 7000)
    {
    # WMI team fixed the formatting issue related to InstalledOn
    # property in Windows7 (to return string)..so returning the WMI's
    # version directly
    [DateTime]::Parse($this.psBase.properties["InstalledOn"].Value)
    }
    else
    {
    $orig = $this.psBase.properties["InstalledOn"].Value
    $date = [datetime]::FromFileTimeUTC($("0x" + $orig))
    if ($date -lt "1/1/1980")
    {
    if ($orig -match "([0-9]{4})([01][0-9])([012][0-9])")
    {
    new-object datetime @([int]$matches[1], [int]$matches[2], [int]$matches[3])
    }
    }
    else
    {
    $date
    }
    };}

    In my case, my locale is set as en-GB (UK locale) however, upon checking the values for InstalledOn the dates were formatted in mm/dd/yyyy, causing an error in parsing the string value to a datetime property with the parse method (as seen above which the scriptproperty is based on), hence the InstalledOn property appears empty. Here's what I did to work around this:

    Get-HotFix | Select-Object description,hotfixid,installedby,
    @{l="InstalledOn";e={
    [DateTime]::Parse($_.psbase.properties["installedon"].value,
    $([System.Globalization.CultureInfo]::GetCultureInfo("en-US")))}}

    FYI I did this all on one line but sometimes on this forum if the line is too long it will go off screen so I separated it onto multiple lines.

  • Thanks very much Pyro3113 it works a treat.

    I was using a regex to switch the MM/DD to DD/MM but after the select, I think this was my issue as although it would sorted out the dates for the ones I did manage to retrieve it did not help on the ones did not.

    I really like the use of

    ::Parse($_.psbase.properties["installedon"].value,$([System.Globalization.CultureInfo]::GetCultureInfo("en-US")

    That is very elegant, great peace of code, thanks

    I learned about the static parse method of the datetime type from NoHandle on this forum, I then learned about the [System.Globalization.CultureInfo]::GetCultureInfo (I believe from one of the excellent tips posted out by this site or possible Ed Wilson blog) e.g.

    ([System.Globalization.CultureInfo]::GetCultureInfo('en-GB')).DateTimeFormat

    But I was not sure how/when to put them together to solve a problem, new we have a live example.

    Nice one, thanks again

    Ernie

     

     

  • I wonder if there would be any way to fix this by adding custom typedata? I haven't found much information yet but still searching...

  • Very nice Pyro. 

    If the source format is always en-US then this should also work: Get-HotFix | Select-Object @{l="InstalledOn";e={[DateTime]$_.psbase.properties["installedon"].value}}

    I am not sure what you mean by custom typedata, though. Can you describe it in more detail, please?

  • Hello NoHandle

     

    I believe Thomas Lee did a video about adding custom type data over at PluralSight.com (I skimmed over it) If I find it I will let you know.

    Ernie

  • Another curiosity, since my computer is set as en-GB, my date formats should all be in dd/mm/yyyy, however all date values for the installedon property in win32_quickfixengineering on my computer are mm/dd/yyyy. I haven't checked any other WMI classes, however most other WMI classes don't use a text format to store date/time information, win32_quickfixengineering must be somewhat unique in that respect.

    by custom type data I mean using a ps1xml file to create your own custom typedata and apply it to the specific data type. I've seen this work for adding properties or methods to data types but I wasn't able to effectively replace the data type for this in my console. I was able to successfully create an additional property.

    Here's the ps1xml I've created. http://sdrv.ms/12yC2zX

    Basically to add this type you need to run Update-TypeData -PrependPath C:\ps\mytypes.ps1xml

    Then you can see this property by using select-object

    get-hotfix | select description,hotfixid,installedby,installedondate

Reply
  • Another curiosity, since my computer is set as en-GB, my date formats should all be in dd/mm/yyyy, however all date values for the installedon property in win32_quickfixengineering on my computer are mm/dd/yyyy. I haven't checked any other WMI classes, however most other WMI classes don't use a text format to store date/time information, win32_quickfixengineering must be somewhat unique in that respect.

    by custom type data I mean using a ps1xml file to create your own custom typedata and apply it to the specific data type. I've seen this work for adding properties or methods to data types but I wasn't able to effectively replace the data type for this in my console. I was able to successfully create an additional property.

    Here's the ps1xml I've created. http://sdrv.ms/12yC2zX

    Basically to add this type you need to run Update-TypeData -PrependPath C:\ps\mytypes.ps1xml

    Then you can see this property by using select-object

    get-hotfix | select description,hotfixid,installedby,installedondate

Children
No Data