Sometimes, you want to hand over a .rtsz file but strip all passwords before doing that.
This can be quickly done by using the following PowerShell script.
Make sure you:
- configure the script by adapting the variables
- always work with a copy of the
.rtszfile so that unintended changes don’t destroy your file
Please note that the following variables need to be altered:
$documentPath= The path to your .rtsz file$outDocumentPath= The path to the new password stripped .rtsz file$documentPasswordPlain= The current password used to lock the .rtsz file$LockdownPasswordPlain= The current lockdown password (uncomment all lockdown references and refer to the remarks in the script)
# Uncomment the following line if you want to use the module which ships with Royal TS V4
# If so, remove the Install-Module and Import-Module command below
# Import-Module "${env:ProgramFiles(x86)}\code4ward.net\Royal TS V4\RoyalDocument.PowerShell.dll"
Install-Module -Name RoyalDocument.PowerShell -Scope CurrentUser
Import-Module -Name RoyalDocument.PowerShell
# configuration of the script
$documentPath = "document.rtsz"
$outDocumentPath = "document_cleaned.rtsz"
$documentPasswordPlain = "pwd_to_open_doc"
# $LockdownPasswordPlain = "lockdown_pwd"
$newPassword = ""
# create a RoyalStore in memory
$royalStore = New-RoyalStore -UserName ($env:USERDOMAIN + '\' + $env:USERNAME)
# load a RoyalDocument in memory
$documentPassword = $documentPasswordPlain | ConvertTo-SecureString -Force -AsPlainText
# Uncomment the following line if your document uses a Lockdown Password
# $LockdownPassword = $LockdownPasswordPlain | ConvertTo-SecureString -Force -AsPlainText
# Comment the following line if your document uses a Lockdown Password
$royalDocument = Open-RoyalDocument -Store $royalStore -FileName $documentPath -Password $documentPassword
# Uncomment the following line if your document uses a Lockdown Password
#$royalDocument = Open-RoyalDocument -Store $royalStore -FileName $documentPath -Password $documentPassword -LockdownPassword $LockdownPassword
# get all password properties and change the password
$passwords = $royalDocument.GetAllPasswordProperties()
foreach ($p in $passwords)
{
$obj = $p.Item1
$pwd = $p.Item2
if($pwd)
{
$obj.SetPropertyValue($pwd, $newPassword)
Write-Host "Resetting password for $($obj.Name) for $($pwd.Name)"
}
}
Out-RoyalDocument -Document $royalDocument -FileName $outDocumentPath
Close-RoyalDocument -Document $royalDocument