只需从Json文件中获取一些内容

只需从Json文件中获取一些内容,json,powershell,Json,Powershell,我只需要从JSON内容中获取一些信息,但是使用普通的select object和where object时,我的PowerShell提示符不会显示任何信息 我所做的: 我从网页获得JSON输出,然后只需要.Content $get_all_attributes = $result.Content | Out-String | ConvertFrom-Json | Select Attributes 当要求PowerShell为我提供一个特定对象时,如$get\u all\u attribute

我只需要从JSON内容中获取一些信息,但是使用普通的
select object
where object
时,我的PowerShell提示符不会显示任何信息

我所做的:

我从网页获得JSON输出,然后只需要.Content

$get_all_attributes = $result.Content | Out-String | ConvertFrom-Json | Select Attributes
当要求PowerShell为我提供一个特定对象时,如
$get\u all\u attributes.attributes.Slot1
一切正常

但是现在我需要获得所有没有
Bif
的插槽(Slot1-SlotX)(例如
Slot1
但不是
Slot1Bif
)。 之后我喜欢找到所有残疾的人。 但现在,我甚至没有得到插槽

我以某种方式将它从Json转换为字符串之类的东西,但现在我有点卡住了

漂亮的JSON

{
"Attributes":  {
                   "AcPwrRcvry":  "Last",
                   "AcPwrRcvryDelay":  "Immediate",
                   "AesNi":  "Enabled",
                   "AssetTag":  "",
                   "BootMode":  "Uefi",
                   "BootSeqRetry":  "Enabled",
                   "CollaborativeCpuPerfCtrl":  "Disabled",
                   "ConTermType":  "Vt100Vt220",
                   "ControlledTurbo":  "Disabled",
                   "Slot1":  "Enabled",
                   "Slot1Bif":  "DefaultBifurcation",
                   "Slot2":  "Enabled",
                   "Slot2Bif":  "DefaultBifurcation",
                   "Slot3":  "Enabled",
                   "Slot3Bif":  "DefaultBifurcation",
                   "Slot4":  "Enabled",
                   "Slot4Bif":  "DefaultBifurcation",
                   "Slot5":  "Enabled",
                   "Slot5Bif":  "DefaultBifurcation",
                   "Slot6":  "Enabled",
                   "Slot6Bif":  "DefaultBifurcation",
                   "Slot7":  "Enabled",
                   "Slot7Bif":  "DefaultBifurcation"
               }
}
我改装的东西

$get_all_attributes | FL

Attributes : @{AcPwrRcvry=Last; AcPwrRcvryDelay=Immediate; AesNi=Enabled; AssetTag=; BootMode=Uefi; BootSeqRetry=Enabled; CollaborativeCpuPerfCtrl=Disabled; 
         ConTermType=Vt100Vt220; ControlledTurbo=Disabled; CorrEccSmi=Enabled; CpuInterconnectBusLinkPower=Enabled; CurrentEmbVideoState=Enabled; 
         DcuIpPrefetcher=Enabled;Slot1=Enabled; Slot1Bif=DefaultBifurcation; Slot2=Enabled; Slot2Bif=DefaultBifurcation; Slot3=Enabled; Slot3Bif=DefaultBifurcation; Slot4=Enabled; 
         Slot4Bif=DefaultBifurcation; Slot5=Enabled; Slot5Bif=DefaultBifurcation; Slot6=Enabled; Slot6Bif=DefaultBifurcation; Slot7=Enabled; 
         Slot7Bif=DefaultBifurcation}

下面的代码应该可以解决您的问题

$attributes = $get_all_attributes.Attributes;
$filteredAttributes = $attributes | Select-Object -Property "slot*" -ExcludeProperty "*Bif";
$slots = @{};
$filteredAttributes.psobject.properties | Foreach { $slots[$_.Name] = $_.Value };
$disabledSlots = $slots.GetEnumerator() |? Value -eq "Disabled";

您就快到了,只需使用开关“ExpandProperty”

$get_all_attributes=$result.Content | Out String | ConvertFrom Json | Select-ExpandProperty attributes

在此之后,最简单的方法就是简单地选择您感兴趣的属性,以获取所有字段。。。
$get\u all\u attributes.attributes.BootSeqRetry

。。。或者为特定子属性获取更细粒度:

$get\u all\u attributes.attributes.BootSeqRetry


(在本例中,它返回启用的

非常感谢您解决了它!让我的日子过得更好:)