如何使用 powershell 更新 xml 属性值

How to update the xml attribute values using powershell

我将 $SourceFileName 作为 studentpackage.zip 传递并将 zip 复制到下面两个 location.how 以在 $SourceFileName[=16= 发生变化时更新 xml 属性 configsolutionfile ]

function BuildArchive          
{            
    param            
    (            
        [parameter(Mandatory=$true)]            
        [ValidateNotNullOrEmpty()]             
        [String] $SourceFileName = ""                                                    
    )  
}

D:\StudentProgram\Automate\Publishing\Content\Forums\StudentPackage 包含一个 xml 文件,我需要在其中更新属性 configsolutionfile

<?xml?>
<config>
  <solutions>
    <configsolutionfile solutionpackagefilename="studentpackage.zip" />
  </solutions>
</config>

D:\StudentProgram\Automate\Publishing\Content\Archives\StudentPackage 包含一个 xml 文件,我需要在其中更新属性 configsolutionfile

<?xml?>
<config>
  <solutions>
    <configsolutionfile solutionpackagefilename="studentpackage.zip" />
  </solutions>
</config>

你可以这样做:

[xml]$xml_contents = Get-Content 'path to XML'
$xml_contents.config.solutions.configsolutionfile.solutionpackagefilename = 'test'
$xml_contents.Save('Path to new XML')