0

Need Windows Update Install Date from Get-Package SwidTagText object. The object is in XML format and everything I have tried to convert doesn't work.

I am trying to switch from WMI because its terribly slow to pull back results.

Tried the ConvertFrom-XML function. Also tried ConvertFrom-String

Get-Package -ProviderName msu | Select-Object *
PropertyOfSoftwareIdentity : PropertyOfSoftwareIdentity
FastPackageReference       : Definition Update for Windows Defender Antivirus - KB2267602 (Definition 1.297.486.0)
ProviderName               : msu
Source                     : 
Status                     : Installed
SearchKey                  : 
FullPath                   : ?
PackageFilename            : ?
FromTrustedSource          : False
Summary                    : Install this update to revise the definition files that are used to detect viruses, spyware, and other potentially 
                             unwanted software. Once you have installed this item, it cannot be removed.
SwidTags                   : {Definition Update for Windows Defender Antivirus - KB2267602 (Definition 1.297.486.0)}
CanonicalId                : msu:Definition Update for Windows Defender Antivirus - KB2267602 (Definition 1.297.486.0)
Metadata                   : {summary,SupportUrl,Date,ResultCode}
SwidTagText                : <?xml version="1.0" encoding="utf-16" standalone="yes"?>
                             <SoftwareIdentity
                               name="Definition Update for Windows Defender Antivirus - KB2267602 (Definition 1.297.486.0)" 
                             xmlns="http://standards.iso.org/iso/19770/-2/2015/schema.xsd">
                               <Meta
                                 summary="Install this update to revise the definition files that are used to detect viruses, spyware, and other 
                             potentially unwanted software. Once you have installed this item, it cannot be removed."
                                 SupportUrl="https://go.microsoft.com/fwlink/?LinkId=52661"
                                 Date="7/5/2019 6:17:09 PM"
                                 ResultCode="2" />
                             </SoftwareIdentity>
Dependencies               : {}
IsCorpus                   : 
Name                       : Definition Update for Windows Defender Antivirus - KB2267602 (Definition 1.297.486.0)
Version                    :
n8kc
  • 1
  • 2
  • Can you be more specific about what you want? It doesn't seem that a raw list of dates for all returned results would be useful but if that's what you're trying to accomplish please specify that. – Dusty Vargas Jul 09 '19 at 22:58

3 Answers3

0

If you're trying to get the raw dates out of the XML you could do something like this:

$xml = ((Get-Package -ProviderName msu) | Select-Object *).SwidTagText
foreach ($item in $xml)
    {
    $(
        $(
            [xml]$item | Select-Object "InnerXml"
        ).InnerXml | Select-Xml -XPath "//*[@Date]"
    ).Node.Date
    }

This gives you each entry to work with like so:

PS C:\Users\Skuld> $xml[0]
<?xml version="1.0" encoding="utf-16" standalone="yes"?>
<SoftwareIdentity
  name="Update for Windows Defender Antivirus antimalware platform - KB4052623 
(Version 4.18.1906.3)" xmlns="http://standards.iso.org/iso/19770/-2/2015/schema.xsd">
  <Meta
   summary="This package will update Windows Defender Antivirus antimalware 
platform’s components on the user machine."
    SupportUrl="https://go.microsoft.com/fwlink/?linkid=862339"
    Date="09/07/2019 10:46:52"
    ResultCode="2" />
</SoftwareIdentity>

You then use Select-XML/XPath to pick out the specific date attribute.

My example will give just a list of all the dates, but you could tweak it if you need extra information along side it.

Skuld
  • 123
  • 1
  • 6
0

Your code worked and now I make a function that searches for specific items inside the SwidTagText

Truly, Powershell is magical

victor
  • 1
  • 1
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 06 '22 at 15:39
0

#Use as much detail as possible. Can't process Arrays yet....

#Example = Get-Package -name "Application Name" | Where-Object { $_.ProviderName -eq "Programs" } | fl *

#Example = Get-Package -name "Application Name" | Where-Object { $_.ProviderName -eq "msi" } | fl *

#Returns any variable from XML SwidTagText

function SwidTagText-XML-Variable ( [string] $PackageName , [string] $XMLName, [string] $PackageType ) 
{

    $PackageObject = Get-Package -name $PackageName |  Where-Object { $_.ProviderName -eq $PackageType }
    
    $xml= $PackageObject.SwidTagText
     
        foreach ($item in $xml)
            {
            $XMLValue = $(
                $(
                    [xml]$item | Select-Object "InnerXml"
                ).InnerXml | Select-Xml -XPath "//*[@$XMLName]"
            ).Node.$XMLName
            }

    
    return $XMLValue

}

#Example of Ubisoft Program and check for UninstallString
SwidTagText-XML-Variable "*ubisoft*" "UninstallString" "Programs"

So the function will search for an XML item inside the SwidTagText. Parsing and getting XML items from this is so useful

victor
  • 1
  • 1