-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPDF-Password-Encryption.ps1
More file actions
28 lines (20 loc) · 1.01 KB
/
Copy pathPDF-Password-Encryption.ps1
File metadata and controls
28 lines (20 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Prompt the user for PDF folder and password input
$pdfFolder = Read-Host -Prompt 'Enter the path to the folder containing PDF files'
$password = Read-Host -Prompt 'Enter the password to be applied to the PDF files'
# Get all PDF files in the folder
$pdfFiles = Get-ChildItem -Path $pdfFolder -Filter *.pdf
# Loop through each PDF file and password-protect it
foreach ($pdfFile in $pdfFiles) {
# Define the output file with the same name as the original file
$outputFile = $pdfFile.FullName
# Temporary filename for the original file
$tempFile = "$($pdfFile.FullName).temp"
# Rename the original file
Rename-Item -Path $pdfFile.FullName -NewName $tempFile
# Password-protect the PDF file using QPDF
& qpdf --encrypt $password $password 256 -- "$tempFile" "$outputFile"
# Remove the temporary file
Remove-Item -Path $tempFile -Force
Write-Host "Password protection completed for: $($pdfFile.FullName)"
}
Write-Host "Password protection completed for all PDF files in $pdfFolder."