I have this file structure
In PowerShell my location is set to Folder
. SubSubFolders
has a lot of xml files, and I want to add a line there only if content of version.txt
file is a
and that line doesn't exist there already.
I was able to figure out how to change an xml file in particular SubSubFolder
, but I can't do it when I start in Folder
folder and and taking into consideration version
#here I need to add: only if version.txt content of xml file in parent folder is "a"
$files = Get-ChildItem -Filter *blah.xml -Recurse | Where{!(Select-String -SimpleMatch "AdditionalLine" -Path $_.fullname -Quiet)} | Format-Table FullName
foreach($file in $files)
{
(Get-Content $file.FullName | Foreach-Object { $_
if ($_ -match "AdditionalLineAfterThisLine")
{
"AdditionalLine"
}
}) | Set-Content $file.FullName
}