I have 1 disk, on my home server, which has all my media in, and where my films download to. I wonder if you could suggest a quick way to move files, to different hard drives, on the letter they start with. E.g my H drive has all my media, I would like files beginning with A-F to drive D, files G-L to drive F and files M-Z to drive E. So far I have ‘Move-Item H:\done\C* D:\ -Force’ line for every letter of the alphabet. Just wondered if there was a quicker was of moving the files.
A work colleague provided me with a script, but it doesn't work, and not sure if its me doing something wrong or the script:
#get a list of files at the source
$files = gci H:\done
#loop through each item in the variable "$files" which will then on be referenced to using the variable "$file"
foreach($file in $files){
#assign the drive letter using a switch statement. Switch statements are a quick way to return a new value based on if a condition is met... in this case if the first letter of the input matches the regex statement.
$drive = switch -regex ($file.basename[0]) {
'[A-F]' {'D:\'}
'[G-L]' {'F:\'}
'[M-Z]' {'E:\'}
}
#quick way to show progress
write-host "Moving $($file.Name) to $drive" -f Cyan
#perform the move
Move-Item $file.FullName $drive -Force -Verbose
}