I have a script in Powershell that I'm having some trouble with.
$Path = 'C:\Projects\Powershell\TEst'
$MiddleName = 'torres'
CD $Path
Get-ChildItem .\ -filter *PCPLink*| ForEach-Object {
$content = Get-Content $_.FullName |
ForEach-Object {$_ -replace $MiddleName, $MiddleName[0]} |out-file $_.FullName -force
}
It's pretty straight forward, the issue I'm having is
I need this to look for multiple files that share the filename filter, for each file i need it to spit out a file with the same name and just the first character value $MiddleName truncated. NOT THE ENTIRE FILE
But when I change the script to output $_.Fullname, the files are empty. What am I missing?
So the file would look like
Torres
Tom
Tony
Tickle
I'm expecting
T
Tom
Tony
Tickle
Actual output from this script is Blank
It DOES pick up the two files I have it filtered to match.
$Contentif you are piping toOut-File?