-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNGsearchAndReplace.ps1
More file actions
executable file
·37 lines (25 loc) · 1.2 KB
/
NGsearchAndReplace.ps1
File metadata and controls
executable file
·37 lines (25 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#progamr to search and replace in files for Nation Guard payroll project
CLS
$patterntoReplace = "^(C:\\Test for Peter.*)(\\Images\\.*)$"
$files = gci -Path "C:\Test for Peter\Backup from Lynx2 - Copy - Copy\AnyDoc_Output (Backup)\TXT copy" -Filter "*.txt*"
$outputFile = "C:\Test for Peter\Backup from Lynx2 - Copy - Copy\AnyDoc_Output (Backup)\TXT copy\output.txt"
foreach($file in $files){
Write-Host $file.FullName
Get-Content $file.FullName|
ForEach-Object{
if($_ -match $patterntoReplace){
# Write-Host $Matches[1]
# $oldline = $Matches[1] -replace "\\","\\"
## Write-Host $oldline
$temp = $_ -replace "C:\\Test for Peter\\Backup from Lynx2 - Copy - Copy\\AnyDoc_Output \(Backup\)", "\\lynx2\Customers\NationalGuard-TrainingOrders\AnyDOC_Output"
# Write-Host $temp
Add-Content -path $outputFile -Value $temp
}else{
Add-Content -path $outputFile -Value $_
}
# write-host $file.FullName
}
$holdFileName = $file.Name
Remove-Item -Path $file.FullName
Rename-Item -path $outputFile -NewName $holdFileName
}