Powershell script to change mutliple file names each with unique name to a standard format

I am seeking a script that will do the following:

Take a file folder and rename it to a common standard across the entire organization.
Take each file within a folder and rename it to a common standard using the existing file name.

I actually have the file folder portion completed, as the powershell

Get-ChildItem -Filter "*current*" -Recurse | Rename-Item -NewName {$_.name -replace 'current','old' }

However, the issue is that the file names used are all over the board.  Examples, amongst a horde of others:

Christopher, Jack 4.2014
Christopher, Jack 042014
Christopher Jack 04-02-2014
Jack Christopher April 2014

What I would like to do is implement a standard of:

JChristopher 042014

So the script should look at the entire file name and then rename it accordingly.

Yes.  There are subfolders sometimes 4 layers deep in some instances, and I can address that separately.

However, there are literally 8K files (not file size), but files that need to meet this new standard.

It's a non-profit who were erroneously informed that they did NOT have to meet HIPPA requirements even though they work with PHI of SP adults.

I know this should be simple, with everything else that is going on, I figured it wouldn't hurt to just ask.  Perhaps someone has already encountered something similar?

Server 2012R2, workstations all running W10Pro.

Thanks,

René
alejansalinAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

aikimarkCommented:
Does the date pattern correlate to the firstname/lastname relationship for that line?

In your example, the only line in firstname lastname order has a date of April 2014
All the other date formats are in lastname firstname order.
Chirag NagrekarSystem AnalystCommented:
Christopher, Jack 4.2014
Christopher, Jack 042014
Christopher Jack 04-02-2014
Jack Christopher April 2014

These are only 4 formats of file name ? If there are many like this then it is very difficult (almost impossible) to rename files because you don't know how many conditions you want to put ?

Second scenario if your file names are in this 4 formats only then you can apply multiple conditions and then rename.

Third is if your files are corresponding to user related folder then you can rename files according to username with your mentioned format.

We can guess many multiple possibilities here but thing is how we can sort this out simply.
aikimarkCommented:
Here's a proof of concept PS script you can play with.  Add additional file names to the array at the top.  Add cases to the switch statement.
NOTE:  I've left the commented write-host statements to help with your testing.
$a = @('Christopher, Jack 4.2014','Christopher, Jack 042014',
       'Christopher Jack 04-02-2014','Jack Christopher April 2014')
       
$a | %{
    switch -regex ($_){
        "^([^, ]+),? ([^ ]+) (\d\.\d{4})$"{
                #write-host "LN:"$matches[1],
                #"FN:"$matches[2][0],
                #"Dt:"$(("0", $($matches[3][0]), ($matches[3][-4..-1] -join '')) -join '') ;
                $newname = $matches[2][0]+$matches[1]+$(("0", $($matches[3][0]), ($matches[3][-4..-1] -join '')) -join '')
                write-host $newname
                break}
        "^([^, ]+),? ([^ ]+) (\d{6})$"{
                #write-host "LN:"$matches[1],
                #"FN:"$matches[2][0],
                #"Dt:"$matches[3];
                $newname = $matches[2][0]+$matches[1]+$matches[3]
                write-host $newname
                break}
        "^([^, ]+),? ([^ ]+) (\d\d-\d\d-\d{4})$"{
                #write-host "LN:"$matches[1],
                #"FN:"$matches[2][0],
                #"Dt:"(($matches[3][0..1] -join ''), ($matches[3][-4..-1] -join '') -join ''); 
                $newname = $matches[2][0]+$matches[1]+(($matches[3][0..1] -join ''), ($matches[3][-4..-1] -join '') -join '')
                write-host $newname
                break}
        "^([^ ]+) ([^ ]+) (\w+ \d{4})$"{
                #write-host "LN:"$matches[2],
                #"FN:"$matches[1][0],
                #"Dt:"([datetime]$matches[3]).tostring("MMyyyy"); 
                $newname = $matches[1][0]+$matches[2]+([datetime]$matches[3]).tostring("MMyyyy")
                write-host $newname
                break}
        default {write-host "not matched"; break}
        }
        
    }

Open in new window

aikimarkCommented:
@alejansalin

Have you abandoned your question?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.