在PowerShell中清洁输出XML数据的解决方案

问题描述 投票:0回答:1

我有一个XML文件,其中包含PowerShell脚本的各种选项,我正在寻找一种干净,简单的方法来在脚本执行开始时输出它们。我不想使用特殊的模块。

XML基本上看起来像这样:

[xml]$Xml = @"
<?xml version="1.0" encoding="utf-8"?>
<Parent>
  <Option1>Value</Option1>
  <Option2>True</Option2>
  <NestedOption>
    <NestedOption1>Value</NestedOption1>
    <NestedOption2>Value</NestedOption2>
  </NestedOption>
  <Option3>Value</Option3>
</Parent>
"@

$Xml.Parent

如您所见,嵌套节点也包含数据。 (1级)我环顾四周,但找不到在PowerShell中输出此内容的好方法。也许有内置函数,或者有人已经创建了解决方案?当然,不应以某种方式静态定义输出。

最佳输出看起来有点像下面“ Get-WindowsFeature”的输出:

Output of "Get-WindowsFeature"

谢谢

powershell
1个回答
0
投票

使用属性表达式尝试Format-Table cmdlet:

Format-Table
© www.soinside.com 2019 - 2024. All rights reserved.