I have a powershell script that goes into a files, and for every instance of E:, it will replace it with CBM-FS01|2013-02-03|E:
$filenames = @("C:\SCRIPT\CBM-FS01-E-20130203114114.txt.out")
foreach ($file in $filenames) {
$outfile = "$file" + ".sql"
Get-Content $file | Foreach-object {
$_ -replace "E:","CBM-FS01|2013-02-03|E:" `
} | Set-Content $outfile
}
If you look close, you can see that I'm getting this information based on the file name. The file name will always be MNEMONIC-MACHINE-DRIVE-YYYMMDDHHMMSS.txt.
Modifying the script for a few files is fine, but I could potentially need to run this on a hundred files! Is there a way using powershell to use the GET-CHILDITEM cmdlet and have powershell automatically perform the -replace based on the different file names?
EDIT: I need to extract parts of the file name, and insert it into the file. For example, for a file CBM-FS01-E-20130203114114.txt, I need to extract the mnemonic-machine (CBM-FS01) and the YYYMMDD (2013-02-03) into the file. Hence
$_ -replace "E:","CBM-FS01|2013-02-03|E:" `