I’m new to Powershell, but I’m trying to create a script that watches over a folder, and move and rename any files in that folder.
The sourcefile is 15x number and a 4 letter ending .pdf.
I need it to move and rename that file to Date+Time+Ending.pdg
So from 123456789128912ABC.pdf
to 181108_0952_ABC.pdf
This is what I have tried to do so far
$source = "C:\script\test\"
$destiantion = "c:\script\"
cd $source
$files = gci -name *.pdf
foreach ($file in $files) {
$thename = $file.substring(20);
$date = Get-Date -f yyMMdd
rename-item -path $source$file -newname $thename
}
This scripts rename the file to ABC.pdf
But my trouble is to add date to the file.
I also want that file moved to $destination after rename.
Anyone who can assist, its probably easy for someone who know this