小编mic*_*a64的帖子

使用 Powershell 编辑 XML 属性

所以我有一个 .exe.config 文件,我试图在其中搜索特定属性,然后在 Windows 7 中使用 Powershell 4.0 版对其进行编辑,但我遇到了问题。我尝试了几件事,但没有任何成功。这是我正在使用的配置文件的精简版本。

<configuration>
  <Config1>
    <section name="text" type="text, text, text=text" allowLocation="true" allowDefinition="Everywhere" allowExeDefinition="MachineToApplication" restartOnExternalChanges="true" requirePermission="true" />
  </Config1>
  <Config2>
    <module debugLogLevel="Debug" Version="1.0.0.0" />
    <Interested-Item attribute-1="text-text" attribute2="0">
    </Interested-Item>
    <modules>
      <add name="something1" />
      <add name="something2" />
      <add name="something3" />
      <add name="something4" />
      <add name="something5" />
      <add name="something6" />
      <add name="something7" />
    </modules>
  </Config2>        
</configuration>
Run Code Online (Sandbox Code Playgroud)

我将如何使用 Powershell 更改感兴趣的项目下的属性 1?任何帮助将不胜感激。

下面是一些我尝试失败的例子。

$File = Get-Content $FileLocation
$XML = [XML]$File

foreach ($attribute in $XML.Config2.Interested-Item)
{
     $attribute = Interested-Item.attribute-1 = "Updated Texted" …
Run Code Online (Sandbox Code Playgroud)

powershell

7
推荐指数
1
解决办法
5624
查看次数

标签 统计

powershell ×1