Question: How can I edit this script so that it only changes the 'Last Modified Date' in the files that it replaces the 'forttester' string in?

How can I edit this script so that it only changes the 'Last Modified Date' in the files that it replaces the 'fort\tester' string in? Right now it modifies the date of all files. Also, I want to replace the string 'fort\tester' with 'fort\success' but it is currently adding an extra slash in 'fort\success' (so it inserts 'fort\\success' instead when it should be just 'fort\success'

$filePath = "C:\Users\Desktop\*.bat" $dateChanged = $false

# Get the files from the folder and iterate using Foreach Get-ChildItem $filePath -Recurse | ForEach-Object { $originalContent = Get-Content $_ $modifiedContent = $originalContent -ireplace 'fort\\tester','fortress\\success'

# Check if the content was modified if ($originalContent -ne $modifiedContent) { $modifiedContent | Set-Content $_ $dateChanged = $true } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!