2023-09-06 11:23:24 -05:00

39 lines
1.6 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";
$outputs = @(); #Keep a record of where our new files are
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; #Extract zip
$outputs += $outputPath;
}
# Process the extracted email files
foreach( $dir in $outputs.GetEnumerator()){
Get-ChildItem "$($dir)\" | Where-Object { $_.name -match '\.eml'} | ForEach-Object{
Copy-Item "$($dir)/$($_.name)" "$($dir)/$($_.name).mht"
}
}
Write-Output Done;