Powershell: Using .Split on Filename functioning differently based on filename capitalization
Thanks to @Lee_Daily
$FileA.BaseName -replace $FileA.Extension, ''
will convert this >>>'IMG_1468.JPG.JPG'
<<< to this >>>'IMG_1468'
<<< after that, you can simply add the .Extension back onto the remaining
I still have no idea why .Split was acting the way it was, but rewriting the $newName definition as advised by @Lee_Daily seems to be agnostic to capitalization (thus solving my root problem):
$newBaseName = $file.BaseName -replace $file.Extension
$newName = $newBaseName+$file.Extension
Write-Host "newName =" $newName
$file | Rename-Item -NewName { $newName } -WhatIf
This now gives me the output I was looking for even when the input is the capitalized value of $FileA:
extCheck = .JPG
oldName = IMG_1468.JPG.JPG
File.Extension = .JPG
newName = IMG_1468.JPG
What if: Performing the operation "Rename File" on target
"Item: \UNC\Path\To\File\IMG_1468.JPG.JPG
Destination: \\UNC\Path\To\File\IMG_1468.JPG".