PowerShell: fixing `Get-HotFix` having empty `InstalledOn` entries
Posted by jpluimers on 2019/11/12
On some systems, Get-HotFix has many entries with an empty InstalledOn column.
This at least shows there is a date-format difference, but now the Source column is empty.:
Get-HotFix | Select-Object Source,Description,HotfixID,InstalledBy,InstalledOn,@{Name="InstalledOnValue";Expression={$_.psbase.properties["InstalledOn"].Value}} | Out-GridView
I contemplated using Microsoft.Update.Session in the scripts below, but it requires WinRM, the server side implementation of WS-Management – Wikipedia:
- [WayBack] Script Get Installed Software Updates Tool
- [WayBack] Find pending updates on local or remote computers | Learn Powershell | Achieve More
- [WayBack] Get List of Installed Windows / Office Updates Command Line through Powershell –
- [WayBack] List updates, hotfixes, and Service Packs with Simple Commands – Simple Talk
[ERROR] [DevMachine] Connecting to remote server DevMachine failed with the following
[ERROR] error message : The client cannot connect to the destination specified in the
[ERROR] request. Verify that the service on the destination is running and is accepting
[ERROR] requests. Consult the logs and documentation for the WS-Management service run
[ERROR] ning on the destination, most commonly IIS or WinRM. If the destination is the
[ERROR] WinRM service, run the following command on the destination to analyze and conf
[ERROR] igure the WinRM service: "winrm quickconfig". For more information, see the abo
[ERROR] ut_Remote_Troubleshooting Help topic.
[ERROR] + CategoryInfo : OpenError: (DevMachine:String) [], PSRemotingTr
[ERROR] ansportException
[ERROR] + FullyQualifiedErrorId : CannotConnect,PSSessionStateBroken
This is a reminder to find and document a proper fix for this.
This at least works:
Get-HotFix | Select-Object Source,Description,HotfixID,InstalledBy,InstalledOn,@{Name="InstalledOnDateTime";Expression={[System.DateTime]::Parse($_.PSBase.Properties["InstalledOn"].Value,[System.Globalization.CultureInfo]::GetCultureInfo("en-US"))}} | Out-GridView
Some links that hopefully help with proper documenting it:
- [WayBack] Get-HotFix
- [WayBack] Win32_QuickFixEngineering class (Windows)
- [WayBack] Select-Object
- [WayBack] Get-Culture
- [WayBack] PSMemberTypes Enum (System.Management.Automation) | Microsoft Docs
- [WayBack] Update-TypeData
-Process:- [WayBack] DateTime Constructor (Int32, Int32, Int32) (System)
- [WayBack] Get-Hotfix cmdlet will not return dates
- [WayBack] Get Hotfixes on Server 2008 Powershell – Super User
- [WayBack] Region specific date formats – Incorrect InstalledOn date from Get-Hotfix
- [WayBack] Topic: Modifying PowerShell script for listing latest windows update on each servers
- [original WayBack] and since Idera loves link-rot, it took me quite a bit of effort to find [WayBack] Get-HotFix and get-WmiObject Win32_QuickFixEngineering missing InstalledOn property – PowerShell General – Ask the Experts – IDERA Community
- [Archive.is] Powershell Get Hotfix Script – administrator.de
PSBase:
–jeroen
Oh nice InstalledOn is a ScriptProperty that assumes Win32_QuickFixEngineering returns InstalledOn in the current locale or is an 8-digit value formatted like YYYYMMDD!
PS C:\Users\Developer> Get-HotFix | Get-Member | Format-List * TypeName : System.Management.ManagementObject#root\cimv2\Win32_QuickFixEngineering Name : PSComputerName MemberType : AliasProperty Definition : PSComputerName = __SERVER TypeName : System.Management.ManagementObject#root\cimv2\Win32_QuickFixEngineering Name : Caption MemberType : Property Definition : string Caption {get;set;} TypeName : System.Management.ManagementObject#root\cimv2\Win32_QuickFixEngineering Name : CSName MemberType : Property Definition : string CSName {get;set;} TypeName : System.Management.ManagementObject#root\cimv2\Win32_QuickFixEngineering Name : Description MemberType : Property Definition : string Description {get;set;} TypeName : System.Management.ManagementObject#root\cimv2\Win32_QuickFixEngineering Name : FixComments MemberType : Property Definition : string FixComments {get;set;} TypeName : System.Management.ManagementObject#root\cimv2\Win32_QuickFixEngineering Name : HotFixID MemberType : Property Definition : string HotFixID {get;set;} TypeName : System.Management.ManagementObject#root\cimv2\Win32_QuickFixEngineering Name : InstallDate MemberType : Property Definition : string InstallDate {get;set;} TypeName : System.Management.ManagementObject#root\cimv2\Win32_QuickFixEngineering Name : InstalledBy MemberType : Property Definition : string InstalledBy {get;set;} TypeName : System.Management.ManagementObject#root\cimv2\Win32_QuickFixEngineering Name : Name MemberType : Property Definition : string Name {get;set;} TypeName : System.Management.ManagementObject#root\cimv2\Win32_QuickFixEngineering Name : ServicePackInEffect MemberType : Property Definition : string ServicePackInEffect {get;set;} TypeName : System.Management.ManagementObject#root\cimv2\Win32_QuickFixEngineering Name : Status MemberType : Property Definition : string Status {get;set;} TypeName : System.Management.ManagementObject#root\cimv2\Win32_QuickFixEngineering Name : __CLASS MemberType : Property Definition : string __CLASS {get;set;} TypeName : System.Management.ManagementObject#root\cimv2\Win32_QuickFixEngineering Name : __DERIVATION MemberType : Property Definition : string[] __DERIVATION {get;set;} TypeName : System.Management.ManagementObject#root\cimv2\Win32_QuickFixEngineering Name : __DYNASTY MemberType : Property Definition : string __DYNASTY {get;set;} TypeName : System.Management.ManagementObject#root\cimv2\Win32_QuickFixEngineering Name : __GENUS MemberType : Property Definition : int __GENUS {get;set;} TypeName : System.Management.ManagementObject#root\cimv2\Win32_QuickFixEngineering Name : __NAMESPACE MemberType : Property Definition : string __NAMESPACE {get;set;} TypeName : System.Management.ManagementObject#root\cimv2\Win32_QuickFixEngineering Name : __PATH MemberType : Property Definition : string __PATH {get;set;} TypeName : System.Management.ManagementObject#root\cimv2\Win32_QuickFixEngineering Name : __PROPERTY_COUNT MemberType : Property Definition : int __PROPERTY_COUNT {get;set;} TypeName : System.Management.ManagementObject#root\cimv2\Win32_QuickFixEngineering Name : __RELPATH MemberType : Property Definition : string __RELPATH {get;set;} TypeName : System.Management.ManagementObject#root\cimv2\Win32_QuickFixEngineering Name : __SERVER MemberType : Property Definition : string __SERVER {get;set;} TypeName : System.Management.ManagementObject#root\cimv2\Win32_QuickFixEngineering Name : __SUPERCLASS MemberType : Property Definition : string __SUPERCLASS {get;set;} TypeName : System.Management.ManagementObject#root\cimv2\Win32_QuickFixEngineering Name : PSStatus MemberType : PropertySet Definition : PSStatus {__PATH, Status} TypeName : System.Management.ManagementObject#root\cimv2\Win32_QuickFixEngineering Name : ConvertFromDateTime MemberType : ScriptMethod Definition : System.Object ConvertFromDateTime(); TypeName : System.Management.ManagementObject#root\cimv2\Win32_QuickFixEngineering Name : ConvertToDateTime MemberType : ScriptMethod Definition : System.Object ConvertToDateTime(); TypeName : System.Management.ManagementObject#root\cimv2\Win32_QuickFixEngineering Name : InstalledOn MemberType : ScriptProperty 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 } };}







Leave a comment