The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,779 other followers

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:

[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:

–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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

 
%d bloggers like this: