if(embedStylesPrinted != true) {document.write('');}var embedStylesPrinted = true;var content = '
#Get Variables Before Starting Script.
$monthyear=get-date -format Y
$date=get-date -format d
$date=$date -replace "/","-"
$rootpath="C:\\Scripts\\Folders"
$penstick="F:\\"
$7zip="C:\\Program Files\\7-zip"
$pass="password"
#FUNCTIONS
#FUNCTION - Pause (for troubleshooting)
function Pause ($Message="Press any key to continue...")
{
Write-Host -NoNewLine $Message
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
Write-Host ""
}
#FUNCTION - Find Out User's Name
function getname
{
$Global:firstname=read-host "What Is Your Name?"
$firstname=$firstname.ToUpper()
checkfolders
}
#FUNCTION - Check User Has Inserted Flash Drive
function usbin
{
write-host ""
write-host "Checking For USB Flash Drive..."
write-host ""
write-host "Looking for USB Drive at $penstick"
write-host ""
if (test-path $penstick)
{
"USB Drive Found at $penstick - Moving on"
""
getname
}
else
{
"USB Drive Not Found at $penstick - Cannot Continue"
""
start-sleep -s 2
exit
}
}
#FUNCTION - Checks initially to see if the rootpath folder exits, if so, recursively checks through folders until one isn't found, in which case it is created
function checkfolders
{
if (test-path $rootpath\\$firstname)
{
if (test-path $rootpath\\$firstname\\$monthyear)
{
""
"$rootpath\\$firstname\\$monthyear folder exists"
""
if (test-path $rootpath\\$firstname\\$monthyear\\$date)
{
""
"$rootpath\\$firstname\\$monthyear\\$date folder exists"
""
}
else
{
""
"only $rootpath\\$firstname\\$monthyear exists"
""
new-item -path $rootpath\\$firstname\\$monthyear -name $date -type directory
}
}
else
{
""
"only $rootpath\\$firstname exists"
""
new-item -path $rootpath\\$firstname -name $monthyear -type directory
new-item -path $rootpath\\$firstname\\$monthyear -name $date -type directory
}
}
else
{
""
"No Folders Exist - Creating New Folderstructure"
""
#Folder Creation - Creates Folder from $firstname
new-item -path $rootpath -name $firstname -type directory
#Then Creates a sub folder "Month Year"
new-item -path $rootpath\\$firstname -name $monthyear -type directory
#Then sub folder named "Date"
new-item -path $rootpath\\$firstname\\$monthyear -name $date -type directory
}
}
#FUNCTION - Check see if the flash drive 'actually' does exist in the expected location, if so, copy zip.
function checkusb
{
if (test-path $penstick)
{
copy-item $penstick\\export.zip $rootpath\\$firstname\\$monthyear\\$date\\export.zip
""
"Waiting for Item to copy...."
""
start-sleep -s 5
}
else
{
""
"I can't find the USB drive, I am expecting to see it at $penstick - please check and try again."
""
start-sleep -s 2
usbin
}
}
usbin
start-sleep -s 2
checkusb
#Unzip and extract content from export.zip to folder structure.
cd $rootpath\\$firstname\\$monthyear\\$date
&'C:\\Program Files\\7-Zip\\7z.exe' e -p$pass $rootpath\\$firstname\\$monthyear\\$date\\export.zip
remove-item $rootpath\\$firstname\\$monthyear\\$date\\export.zip
remove-item $rootpath\\$firstname\\$monthyear\\$date\\data