KeePass Example PowerShell Scripts
Copyright © 2024-2025 Dominik Reichl.
Distributed under the terms of the
GNU
General Public License v2.
This package contains various examples of scripting KeePass with PowerShell.
General
The example scripts and KeePass are compatible with the PowerShell version
that is included in Windows 10/11. If you want to use a different PowerShell
version, you may need to adjust the scripts/KeePass.
For each example script, there is a corresponding batch file that runs the
script. This is useful on systems where the execution of PowerShell scripts is
disabled by default.
Examples
Each example script calls the '_Common_Initialize.ps1' script at the
beginning and the '_Common_Terminate.ps1' script at the end.
- _Common_Initialize.ps1:
This script loads the KeePass assembly and initializes it.
Note: The assembly is loaded from
'C:\Program Files\KeePass Password Safe 2\KeePass.exe',
which is the path that the setup program uses by default.
If you have installed KeePass to a different directory, you need to either
reinstall KeePass to the default directory or adjust the path in the script file.
- _Common_Terminate.ps1:
This script cleans up.
Example scripts:
- AccessAttachments.ps1:
This script demonstrates how to work with
attachments.
First, it gets an attachment that is stored in the example database file and
saves it to a file.
Second, it adds a new entry that contains the '_ReadMe.html' file as attachment.
- ExportToXml.ps1:
This script opens the example database file and exports all data to an XML file
(file name 'ExportToXml.xml').
- GenerateKeyFile.ps1:
This script generates a new key file (file name 'GenerateKeyFile.keyx').
- GeneratePasswords.ps1:
This script generates some passwords using the
password generator of KeePass.
- GetString.ps1:
This script opens the example database file, searches for an entry with title
'Sample Entry #2' and outputs its user name.
Links
Information about scripting KeePass:
https://keepass.info/help/v2_dev/scr_index.html
Support:
https://sourceforge.net/p/keepass/discussion/329221/
Feature requests & bug reports:
https://sourceforge.net/p/keepass/discussion/329220/
Donate:
https://keepass.info/donate.html