I'd like to write a PowerShell script to extract multiple password-protected .7z files, that have their passwords saved inside a text file that its filename contains the name of the .7z
File structure example:
EncryptedFile1_02192020.7z
EncryptedFile1_password.txt
EncryptedFile2_02192020.7z
EncryptedFile2_password.txt
The script below works only if there are 1 .7z and 1 .txt file in the folder.
$pass = get-content *.txt
7z.exe x *.7z -p"$pass" -o*
Problem: I do not know how to use the combination of foreach and -Like statements to batch extract multiple encrypted files in the working directory. Thanks in advance for your help.