首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Get-Package命令包含xml字符串-需要转换为PSObject

Get-Package命令包含xml字符串-需要转换为PSObject
EN

Stack Overflow用户
提问于 2019-07-10 05:34:54
回答 1查看 215关注 0票数 0

需要来自Get-Package SwidTagText object的Windows Update安装日期。对象是XML格式的,我尝试转换的所有内容都不起作用。

我正在尝试从WMI切换,因为它拉回结果的速度非常慢。

已尝试ConvertFrom-XML函数。我还尝试了ConvertFrom-String

代码语言:javascript
复制
Get-Package -ProviderName msu | Select-Object *
代码语言:javascript
复制
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                    :
EN

回答 1

Stack Overflow用户

发布于 2019-07-10 08:06:46

如果您想从XML中获取原始日期,可以这样做:

代码语言:javascript
复制
$xml = ((Get-Package -ProviderName msu) | Select-Object *).SwidTagText
foreach ($item in $xml)
    {
    $(
        $(
            [xml]$item | Select-Object "InnerXml"
        ).InnerXml | Select-Xml -XPath "//*[@Date]"
    ).Node.Date
    }

这为您提供了每个条目,如下所示:

代码语言:javascript
复制
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>

然后使用Select-XML/XPath选择特定的日期属性。

我的示例将只给出所有日期的列表,但如果需要额外的信息,您可以对其进行调整。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56960794

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档