1

Using the following command on Windows Server 2008-R2 works:

Get-Hotfix -cn HOSTNAME | sort InstalledOn -des  | select HotfixID, Description, InstalledOn -first 20

But does not work on Windows Server 2003 (not surprising) OR Server 2008 32-bit (this is what's odd to me).

I get the following error when I run this script on a 32-bit Win 2008 server:

Sort-Object : Exception setting "InstalledOn": "Exception calling "Parse" with "1" argument(s): "String was not recognized as a valid DateTime.""

2

It's throwing the error because it's failing to sort them by Date/Time due to a hotfix with a InstalledOn entry that can't be parsed into a valid Date/Time.

So, most likely you have HotFixes installed on the one machine that don't have a proper "Installed On Date", and so it just returns blank for those entries.

This is not specific to a version of Windows, as I tested this on a Windows 2012 R2 server, and saw the same error.

You can confirm the InstalledOn dates by running the query without the sort:

Get-Hotfix -cn HOSTNAME | select HotfixID, Description, InstalledOn -first 20

Example:

PS C:\Windows\system32> Get-Hotfix | select HotfixID, Description, InstalledOn -first 20

HotfixID                                Description                             InstalledOn
--------                                -----------                             -----------
KB2868626                               Security Update
KB2883200                               Update
KB2887595                               Update
KB2894852                               Security Update                         01Dec2015 12:00:00 AM
KB2896496                               Update
KB2900986                               Security Update
KB2903939                               Update
KB2904440                               Update
KB2911106                               Update
KB2919355                               Update                                  04Oct2014 12:00:00 AM

Note above that many of them show nothing for InstalledOn.

  • Not the answer I wanted to hear, but did answer my question. Interestingly, this works locally on the 2008 server, just not remotely from a 2008 R2 server. – Brian Henson Oct 22 '15 at 20:09
1

Definitly not the best solution, but works for me:

$lastHotFixInstallDate = Get-HotFix | Select-Object @{ 
    'L' = 'installDate';
    'E' = {
        "{0}-{1:00}-{2:00}" -f `
            [Int]$_.PSBase.Properties["installedon"].value.Split('/')[2], `
            [Int]$_.PSBase.Properties["installedon"].value.Split('/')[0], `
            [Int]$_.PSBase.Properties["installedon"].value.Split('/')[1]}  
}  | Sort-Object -Property installDate | Select-Object -Last 1

This solution utilize the $_.PSBase.Properties["installedon"].value property. Since this property is a string in format m/d/yyyy, it needs to be split manually on the / and sort it afterwards.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.