我正在使用深度嵌套的 JSON,并且在 Convertfrom-json 之后,需要能够遍历 Convertfrom-json cmdlet 生成的对象的各个部分。
我无法提前知道对象内部可能存在或不存在哪些属性名称,据我所知,有数百种不同的可能属性。幸运的是,我看到有帮助的一件事是我关心的每个属性都是“NoteProperty”类型。
这是一个例子:
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()
definition NoteProperty System.Management.Automation.PSCustomObject definition=@{$schema=https://schema.management.azure.com/providers/Microsof...
integrationAccount NoteProperty System.Management.Automation.PSCustomObject integrationAccount=@{id=[parameters('integrationAccounts_xxx_integration...
parameters NoteProperty System.Management.Automation.PSCustomObject parameters=@{$connections=}
state NoteProperty string state=Enabled
Run Code Online (Sandbox Code Playgroud)
因此,我认为创建一个仅选择当前正在处理的级别的对象(“MemberType”“NoteProperty”)的函数会很简单。
我尝试将对象通过管道传输到:
where-object { $_.MemberType -eq "NoteProperty" }
Run Code Online (Sandbox Code Playgroud)
没有。
我也尝试过各种形式的选择对象,但似乎无法选择我需要的东西。我发现脚本人员写的一篇关于使用标签和表达式的旧文章 - 但这似乎有点过头了,不是吗?有人可以指出我仅选择 NoteProperty 项目的简单方法吗?
谢谢!