Ihave been working on a script that will move everything from my downloads folder to another folder on a external drive (We will now call this "Backup Drive"), sorting it into folders by extension (found it on StackOverflow for the initial start --Thanks to Nicola Cossu--). Every once in a while I need to use the script to be able to pull stuff from another drive to the Backup Drive.
I would like to have ONE script that will ask me for Source and Destination drive, but would like it to do is have my Downloads Folder and Backup Drive Folder to be predefined.
One of the ways I thought would work would be to have the dialog box that pops up, have the location of each question already filled to allow me to edit it only when I need to. I am not sure on how to do this.
If it needs to be hard coded to variables $MySRC and $MyDST, that is fine. Thanks in advance!!!
Here is my code:
# Get Start Time of the Script
$startDTM = (Get-Date)
# Get Source and Destination -- this is where I am trying to get the predetermine variables to be
$source = Read-Host "Enter for Source"
$dest = Read-Host "Enter for Destination"
# This could be where my variables are located
# $MySRC = "C:\Users\ME\Downloads"
# $MyDST = "E:\Sorted Downloads"
# Logging information for personal reasons
echo ""
echo "This script is starting"
echo ""
echo "The source is "
$source
echo ""
echo "The destination is "
$dest
echo ""
echo ""
# Actual Script to Run
$file = gci -Recurse $source | ? {-not $_.psiscontainer}
$file | group -property extension |
% {if(!(test-path(join-path $dest -child $_.name.replace('.','')))) { new-item -type directory $(join-path $dest -child $_.name.replace('.','')).toupper() }}
$file | % { move-item $_.fullname -destination $(join-path $dest -child $_.extension.replace(".",""))}
# End of Script Information -- Personal Reasons
echo "This Script is Done!"
echo 'Source: ' $source ' Destination: ' $dest
echo ""
# Get End Time:
$endDTM = (Get-Date)
# Echo Time Elapsed for the Script to Run:
"Elapsed Time: $(($endDTM-$startDTM).totalseconds) seconds"