I have a device the saves all files to a folder(A) on the server, all using the same naming format.
123456_Report
951753_report
741258_report
etc.. Folder(A)
All files / reports are named using 6 unique identifying numbers followed by a description anywhere from 3-20 characters.
Folder(B) contains folders(C-Z) for each file in folder(A). Overall layout of Folders
Folders(C-Z) are named to match the 6 unique identifying numbers at the beginning of each file in Folder(A)
I am trying to create a script to move the files from Folder(A) to its respective Folder(C-Z)
This photo is describes best what I am trying to do
So far what I have figured out moves the files from Folder(A) to Folder(B) –Then– changes it from a .txt file to a generic .file and removes the first position of the file name. I have made changes to the script at one point where it did not remove the first position and it kept it as a .txt file, but it still did not place it into the corresponding folder
What I currently get when I run my script
Before I hit post, I remembered I removed “$foldername from $destinationFolder = “C:TEMP $foldername
”
Any help is greatly appreciated!!!
$Files = Get-ChildItem -Path 'C:TEMP123456'
$Files | ForEach-Object {
$foldername = $_.Name.Substring(1,6)
$destinationFolder = "C:TEMP"
Move-Item $_.FullName $destinationFolder
}