$xml = [xml](Get-Content C:\temp\STA\*.dtsConfig)
$xml.SelectNodes('//ConfiguredValue')|%{$_.'#text'=($_.'#text' -replace '_\d+',[datetime]::Today.ToString('_MMddyyy'))}
$xml.SelectNodes('//ConfiguredValue')|%{$_.'#text'}
xml.Save('C:\temp\STA\*.dtsConfig')
从前3个步骤我想在dtsConfig中的ConfiguredValue中检查标签,命名为PackageDependencies_somedate(20110528),我想更改PackageDependencies_currentdate(20130619), 将某个日期更改为当前日期并保存文件,
答案 0 :(得分:0)
您的代码应如下所示:
ls C:\temp\STA\*.dtsConfig | foreach {
$file = $_.FullName;
$xml = [xml](Get-Content $file)
$todayStr = [datetime]::Today.ToString('_MMddyyy')
@($xml.SelectNodes('//ConfiguredValue')) | %{
$_.'#text'=($_.'#text' -replace '_\d+',$todayStr)
}
$xml.Save($file)
}