so I use PDFTK to bulk password generate and protect pdfs and store the name and password in an Excel file. But every time there is a [ ] in the file name, the file is skipped/the script doesn't work.
$password_file="output\passwords.xlsx"
Remove-Item $password_file -ErrorAction Ignore
Get-ChildItem "input\*.pdf" | % {
$inp_file=$_
$out_file="output\" + (Get-Item $inp_file).Basename + ".pdf"
# Create pasword and write to password file
$tmp_password_file="output\tmp_pwd.txt"
Remove-Item $tmp_password_file -ErrorAction Ignore
$password=-join ("!?@#$%^&0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz".tochararray() | ForEach-Object {[char]$_} | Get-Random -Count 16)
$password > $tmp_password_file
# Read the password from the (just created) password file
$pwd=Get-Content $tmp_password_file
# Encrypt the pdf file
pdftk $inp_file output $out_file user_pw $pwd
# write pdf filename and password to file
$zz=(Get-Item $inp_file).Basename + "," + $pwd.ToString()
Add-Content $password_file $zz
}
How can I fix this? Thanks in advance!