Audrey Aaliyah Jensen 647bcdfe53 unzip files to desktop
2023-08-28 10:17:25 -05:00

30 lines
1.3 KiB
PowerShell

# Regex the password from the zip's filename. Copy to var
# Open 7zip, extract to desktop, input password.
# take all *.eml and make .mht copies.
#Copy items to desktop
Copy-Item './extract.py' '..';
#Get-ChildItem | Where-Object { $_.name -match '\.zip'} | ForEach-Object {Copy-Item -Path $_.name -Destination '..' }
#Capture zip password from filename
$pwPattern = [regex] "[A-z 0-9 \-]{1,251}\((?<PW>[A-z0-9]{1,251})\)\.zip";
$files = @{};
Get-ChildItem './Sandbox Scripts'| Where-Object { $_.name -match '\.zip'} | ForEach-Object {
$pass = [Regex]::Matches($_, $pwPattern);
$files.Add($_.name, $pass.groups[1].Value);
}
#Install 7Zip and extract the zip files to the desktop.
Write-Output "Installing Programs...";
Start-Process "C:\Users\WDAGUtilityAccount\Desktop\Sandbox Scripts\7zip.exe" -NoNewWindow -Wait -ArgumentList /S;
$sevenZip = "C:\Program Files\7-Zip\7z.exe";
foreach ($file in $files.GetEnumerator()){
Write-Output "Extracting $($file.Name)";
$archivePath = "C:\Users\WDAGUtilityAccount\Desktop\Sandbox Scripts\$($file.Name)"
$outputPath = "C:\Users\WDAGUtilityAccount\Desktop\$($file.Name)";
$password = $($file.Value);
$arguments = "$($archivePath)", "-o$($outputPath)", "-p$($password)";
&$sevenZip e $arguments;
}
Write-Output Done;