首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >返回不匹配值的Powershell对象

返回不匹配值的Powershell对象
EN

Stack Overflow用户
提问于 2022-10-07 09:24:12
回答 1查看 57关注 0票数 1

我有一个PSObjects哈希表,该哈希表包含有关widnows修补程序和CVE编号的信息,它采用以下格式:

代码语言:javascript
复制
ID                  : 2022-Sep
InitialRealeaseDate : 13/09/2022 07:00:00
CvrfUrl             : https://api.msrc.microsoft.com/cvrf/v2.0/document/2022-Sep
Severity            :
DocumentTitle       : September 2022 Security Updates
cve                 : CVE-2022-37969
Alias               : 2022-Sep
CurrentReleaseDate  : 04/10/2022 07:00:00

我正在尝试提取具有匹配CVE的记录。我认为他应该工作:

代码语言:javascript
复制
$results | where {$results.cve -eq 'CVE-2022-38006'}

但是它返回许多记录(包括正确的记录),但是对于大多数情况下,$records.cve元素与请求的过滤器完全没有任何共同点,我不希望它被返回。

代码语言:javascript
复制
ID                  : 2022-Sep
InitialRealeaseDate : 13/09/2022 07:00:00
CvrfUrl             : https://api.msrc.microsoft.com/cvrf/v2.0/document/2022-Sep
Severity            :
DocumentTitle       : September 2022 Security Updates
cve                 : CVE-2022-37969
Alias               : 2022-Sep
CurrentReleaseDate  : 04/10/2022 07:00:00

ID                  : 2022-Sep
InitialRealeaseDate : 13/09/2022 07:00:00
CvrfUrl             : https://api.msrc.microsoft.com/cvrf/v2.0/document/2022-Sep
Severity            :
DocumentTitle       : September 2022 Security Updates
cve                 : CVE-2022-38004
Alias               : 2022-Sep
CurrentReleaseDate  : 04/10/2022 07:00:00

ID                  : 2022-Sep
InitialRealeaseDate : 13/09/2022 07:00:00
CvrfUrl             : https://api.msrc.microsoft.com/cvrf/v2.0/document/2022-Sep
Severity            :
DocumentTitle       : September 2022 Security Updates
cve                 : CVE-2022-38005
Alias               : 2022-Sep
CurrentReleaseDate  : 04/10/2022 07:00:00

ID                  : 2022-Sep
InitialRealeaseDate : 13/09/2022 07:00:00
CvrfUrl             : https://api.msrc.microsoft.com/cvrf/v2.0/document/2022-Sep
Severity            :
DocumentTitle       : September 2022 Security Updates
cve                 : CVE-2022-38006
Alias               : 2022-Sep
CurrentReleaseDate  : 04/10/2022 07:00:00

Get成员说CVE元素是一个字符串:

代码语言:javascript
复制
PS E:\Scripts\Ian\GIT\XDR> $results | gm

   TypeName: System.Management.Automation.PSCustomObject

Name                MemberType   Definition
----                ----------   ----------
Equals              Method       bool Equals(System.Object obj)
GetHashCode         Method       int GetHashCode()
GetType             Method       type GetType()
ToString            Method       string ToString()
Alias               NoteProperty string Alias=2022-Sep
CurrentReleaseDate  NoteProperty string CurrentReleaseDate=04/10/2022 07:00:00
cve                 NoteProperty string cve=
CvrfUrl             NoteProperty string CvrfUrl=https://api.msrc.microsoft.com/cvrf/v2.0/document/2022-Sep
DocumentTitle       NoteProperty string DocumentTitle=September 2022 Security Updates
ID                  NoteProperty string ID=2022-Sep
InitialRealeaseDate NoteProperty string InitialRealeaseDate=13/09/2022 07:00:00
Severity            NoteProperty string Severity=

我做错了什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-10-07 09:32:58

而不是:

代码语言:javascript
复制
$results | where {$results.cve -eq 'CVE-2022-38006'}

尝试:

代码语言:javascript
复制
$results | where {$_.cve -eq 'CVE-2022-38006'}

或者更简单地说:

代码语言:javascript
复制
$results | where cve -eq 'CVE-2022-38006'
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73985047

复制
相关文章

相似问题

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