Question: How can I get this script to change the 'Date Modified' ONLY in the files that contain the string that is being replaced? $filePath =

How can I get this script to change the 'Date Modified' ONLY in the files that contain the string that is being replaced?

$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','fort\success'

# Check if the content was modified

if ($originalContent -ne $modifiedContent) {

$modifiedContent | Set-Content $_

# set the $dateChanged = true after the modification of the 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!