Sometimes, you want to hand over an .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 .rtsz file so that unintended changes don't destroy your file


  


Import-Module "${env:ProgramFiles(x86)}\code4ward.net\Royal TS V4\RoyalDocument.PowerShell.dll"

# configuration of the script
$documentPath = "document.rtsz"
$outDocumentPath = "document_cleaned.rtsz"
$documentPasswordPlain = "pwd_to_open_doc"
$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
$royalDocument = Open-RoyalDocument -Store $royalStore -FileName $documentPath -Password $documentPassword

# 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