gpt4 book ai didi

json - 如何获取 PSCustomobject 的长度?

转载 作者:行者123 更新时间:2023-12-03 00:25:09 25 4
gpt4 key购买 nike

下面是powershell中存储的

#Maintainer Note: The leftmost parameter must match the registry key name exactly e.g. 'DES 56'
#For more information please check https://support.microsoft.com/en-us/kb/245030
$bannedCiphersJSON = @"
{
"RC4 128/128":{
"IsPermitted":false,
"AffectedCiphers":[
"SSL_RSA_WITH_RC4_128_MD5",
"SSL_RSA_WITH_RC4_128_SHA",
"TLS_RSA_WITH_RC4_128_MD5",
"TLS_RSA_WITH_RC4_128_SHA"
]
},

"Triple DES 168":{
"IsPermitted":false,
"AffectedCiphers":[
"SSL_RSA_WITH_3DES_EDE_CBC_SHA",
"SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA" ,
"TLS_RSA_WITH_3DES_EDE_CBC_SHA" ,
"TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA"
]
},

"RC4 56/128":{
"IsPermitted":false,
"AffectedCiphers":[
"TLS_RSA_EXPORT1024_WITH_RC4_56_SHA"
]
},

"DES 56":{
"IsPermitted":false,
"AffectedCiphers":[
"SSL_RSA_WITH_DES_CBC_SHA"
]
},

"RC4 40/128":{
"IsPermitted":false,
"AffectedCiphers":[
"SSL_RSA_EXPORT_WITH_RC4_40_MD5",
"TLS_RSA_EXPORT_WITH_RC4_40_MD5"
]
},

"RC2 40/128":{
"IsPermitted":false,
"AffectedCiphers":[
"SSL_RSA_EXPORT_WITH_RC2_CBC_40_MD5",
"TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5"
]
},

"MD5":{
"IsPermitted":false,
"AffectedCiphers":[
"SSL_RSA_EXPORT_WITH_RC4_40_MD5",
"SSL_RSA_WITH_RC4_128_MD5",
"SSL_RSA_EXPORT_WITH_RC2_CBC_40_MD5",
"TLS_RSA_EXPORT_WITH_RC4_40_MD5",
"TLS_RSA_WITH_RC4_128_MD5",
"TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5"
]
},

"SHA":{
"IsPermitted":false,
"AffectedCiphers":[
"SSL_RSA_WITH_RC4_128_SHA",
"SSL_RSA_WITH_DES_CBC_SHA",
"SSL_RSA_WITH_3DES_EDE_CBC_SHA",
"SSL_RSA_EXPORT1024_WITH_DES_CBC_SHA",
"SSL_RSA_EXPORT1024_WITH_RC4_56_SHA",
"TLS_RSA_WITH_RC4_128_SHA",
"TLS_RSA_WITH_DES_CBC_SHA",
"TLS_RSA_WITH_3DES_EDE_CBC_SHA",
"TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA",
"TLS_RSA_EXPORT1024_WITH_RC4_56_SHA"
]
}
}
"@

$bannedCiphers =$bannedCiphersJSON | ConvertFrom-Json

function Get-TLSProtocol{

For ($i=0; $i -lt $bannedCiphers.Count; $i++)
{

write-output $i
}
}

Get-TLSProtocol

当我对对象运行 Get-Member 时,每个对象似乎都是一个“注释属性”。因此,我认为数组定义不正确。 (我的目标是获取可用于检查注册表的对象列表。

PS C:\users\golden> $bannedCiphers | get-member


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()
DES 56 NoteProperty System.Management.Automation.PSCustomObject DES 56=@{IsPermitted=False; AffectedCiphers=...
MD5 NoteProperty System.Management.Automation.PSCustomObject MD5=@{IsPermitted=False; AffectedCiphers=Sys...
RC2 40/128 NoteProperty System.Management.Automation.PSCustomObject RC2 40/128=@{IsPermitted=False; AffectedCiph...
RC4 128/128 NoteProperty System.Management.Automation.PSCustomObject RC4 128/128=@{IsPermitted=False; AffectedCip...
RC4 40/128 NoteProperty System.Management.Automation.PSCustomObject RC4 40/128=@{IsPermitted=False; AffectedCiph...
RC4 56/128 NoteProperty System.Management.Automation.PSCustomObject RC4 56/128=@{IsPermitted=False; AffectedCiph...
SHA NoteProperty System.Management.Automation.PSCustomObject SHA=@{IsPermitted=False; AffectedCiphers=Sys...
Triple DES 168 NoteProperty System.Management.Automation.PSCustomObject Triple DES 168=@{IsPermitted=False; Affected...

在 powershell 中定义对象以便我可以遍历最顶层的正确方法是什么?

最佳答案

你有一个 PSCustomObject,而不是一个数组。该对象在属性中隐藏了一些数组,不过。 [grin] 这是获取列表和计数的一种方法......

$AffectedCiphers = foreach ($PropName in $Test.PSObject.Properties.Name)
{
$Test.$PropName.AffectedCiphers
}

'There are {0} ciphers in the Banned Ciphers list.' -f $AffectedCiphers.Count

输出:

There are 30 ciphers in the Banned Ciphers list.

上面的内容:

  • 调用所有 powershell 对象的隐藏 .PSObject 属性
  • 获取父对象中的普通属性列表
  • 遍历列表,获取 .AffectedCiphers 属性值(在本例中为值数组)
  • 将它们保存到 $AffectedCiphers
  • 获取 $AffectedCiphers 中的项目数

希望对你有帮助,

关于json - 如何获取 PSCustomobject 的长度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53103213/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com