<Users>
<Name>$user</Name>
<Gender>Male</Gender>
</Users>
View Code
# D:\Services\ 指定要递归遍历查找的目录
# *.config 找查找的文件名
$fileList = Get-ChildItem 'F:\temp\test\' -recurse *.xml | %{$_.FullName}
$baishi = {$user}
Foreach($file in $fileList)
{
# $tmpXML = [xml](Get-Content $file)
# $tmpXML.users.SID
# $tmpXML.Replace("#user", "Fred")
$tmpXML = [string](Get-Content $file)
$tmpXML = $tmpXML.replace($baishi,"Fred")
Set-Content -Path $file -Value $tmpXML
}
<Users> <Name>Fred</Name> <Gender>Male</Gender> </Users>