如何使用powershell更新xml属性值

如何使用powershell更新xml属性值,powershell,powershell-2.0,powershell-3.0,powershell-4.0,Powershell,Powershell 2.0,Powershell 3.0,Powershell 4.0,我将$SourceFileName作为studentpackage.zip传递,并将zip复制到下面两个位置。当$SourceFileName发生更改时,如何更新xml属性configsolutionfile function BuildArchive { param ( [parameter(Mandatory=$true)] [V

我将$SourceFileName作为studentpackage.zip传递,并将zip复制到下面两个位置。当$SourceFileName发生更改时,如何更新xml属性configsolutionfile

function BuildArchive          
{            
    param            
    (            
        [parameter(Mandatory=$true)]            
        [ValidateNotNullOrEmpty()]             
        [String] $SourceFileName = ""                                                    
    )  
}
D:\StudentProgram\Automation\Publishing\Content\Forums\StudentPackage包含一个xml文件,我需要在其中更新属性
configsolutionfile

<?xml?>
<config>
  <solutions>
    <configsolutionfile solutionpackagefilename="studentpackage.zip" />
  </solutions>
</config>
<?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')
您可以这样做:

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