I have a filename called "Ben_sucksatpowershell_2018_07_13_21_22_07.txt" I'm trying to rename that file to "b.20180713.b"
For the script I am writing I need to rename a series of these files, and the new name needs to be based off the original yyyy_MM_dd in the original file name
I get that I can I replace a chunk of the filename, but I don't know how to strip the underbars, or perform a multiple replace, or rename the file name in the same command. I am still new to powershell. I have been unable to find what I am looking for. I would appreciate guidance, on how to get what I'm seeking.
Foreach ($Slave in $Slaves)
{
$ProcessedPath = "\\$Server\Directory\Processed\"
$ProcessedSlave = "$ProcessedPath\$Slave\"
If (!(Test-Path $ProcessedSlave))
{
Copy-Item -Path $Eticket -Destination $ProcessedPath -Force
ren $Eticket -NewName {$_.Name -replace ("Ben_sucksatpowershel_", "b.") | (".txt",".b")} #of course, this doesn't work though.
}
Else
{
Write-Host "Potato"
}