Console

Single Command Operations


How to use KPScript with single command operations to perform simple database operations.

KPScript can be invoked using single commands. By passing the database location, its key, a command and eventually some parameters, simple operations like adding an entry can be performed. The syntax is very simple, no scripting knowledge is required. This method is ideal when you quickly want to do some small changes to the database. It is not recommended when you need to perform many operations, because for each command the database needs to be loaded from file, decrypted, modified, encrypted and written back to file.

Commands are specified by passing -c:COMMAND to KPScript, where COMMAND is the command to execute (see below for a list of available commands).

The database location is passed to KPScript by just passing it as a parameter, without any option prefix.

The composite key for the database can be given to KPScript using one of the following ways:


Available Commands:

Please note that commands are added incrementally based on user requests. If you are missing a command, please let the KeePass team know and it will be added to the next release of KPScript.

Currently, the following commands are available:


Command: ListGroups

This command lists all groups in a format that easily machine-readable. The output is not intended to be printed/used directly. Usage example:

KPScript -c:ListGroups "C:\KeePass\MyDb.kdbx" -pw:MyPassword
This will list all groups contained in the MyDb.kdbx database file.


Command: ListEntries

This command lists all entries in a format that easily machine-readable. The output is not intended to be printed/used directly. Usage example:

KPScript -c:ListEntries "C:\KeePass\MyDb.kdbx" -pw:MyPassword -keyfile:"C:\KeePass\MyDb.key"
Opens the MyDb.kdbx database using 'MyPassword' as password and the MyDb.key file as key file. It will output a list of all entries contained in the MyDb.kdbx database file.


Command: GetEntryString

Retrieves the value of an entry string field. The entry identification syntax is exactly the same as in the EditEntry command. The field name can be specified using the '-Field' parameter (supported field names are e.g. Title, UserName, Password, URL, Notes, etc.). Usage example:

KPScript -c:GetEntryString "C:\KeePass\MyDb.kdbx" -pw:MyPassword -Field:UserName -ref-Title:"Demo Account"
Opens the MyDb.kdbx database using 'MyPassword' as password. It outputs the user names of all entries that have the title "Demo Account".


Command: AddEntry

This command adds an entry to the database. To specify the entry details, use the standard string field identifiers as parameter names and their values for the contents. Supported standard string fields are: Title, UserName, Password, URL, and Notes. Usage examples:

KPScript -c:AddEntry "C:\KeePass\MyDb.kdbx" -pw:MyPw -Title:"New entry title"

KPScript -c:AddEntry "C:\KeePass\MyDb.kdbx" -pw:MyPw -Title:SomeWebsite -UserName:Don -Password:pao5j3eg -URL:http://website.com

The -GroupName: parameter can be used to specify the group in which the entry is created. For searching, KPScript performs a pre-order traversal and uses the first matching group (the name is case-sensitive). If no group with the specified name is found, it will be created in the root group. If you do not specify a group name, the entry will be created in the root group. Example:

KPScript -c:AddEntry "C:\KeePass\MyDb.kdbx" -pw:MyPw -Title:"My Provider" -GroupName:"Internet Sites"


Command: EditEntry

This command edits existing entries.

To identify the entries to be edited, string fields can be compared. The syntax is -ref-FIELDNAME:FIELDVALUE. Additionally to comparing string fields, some other entry fields can be compared. -refx-UUID: can be used to specify the UUID. -refx-Tags: can be used to specify tags (multiple tags must be separated using commas ',').

To specify one or more new entry string values, use the following syntax: -set-FIELDNAME:FIELDVALUE.

Usage examples:

KPScript -c:EditEntry "C:\KeePass\MyDb.kdbx" -pw:MyPw -ref-Title:"Existing entry title" -set-UserName:"New user name"

KPScript -c:EditEntry "C:\KeePass\MyDb.kdbx" -pw:MyPw -ref-UserName:MyName -set-UserName:NewName -set-Password:"Top Secret"

If you additionally pass -CreateBackup, KPScript will first create backups of entries before modifying them.


Command: MoveEntry

This command moves one or more existing entries. The entry identification syntax is exactly the same as in the EditEntry command.

The target group can be specified using the GroupTree parameter. '/' must be used as separator (e.g. -GroupTree:Internet/eMail moves the specified entries to the subgroup 'eMail' of the subgroup 'Internet').


Command: DeleteEntry

This command deletes one or more existing entries. The entry identification syntax is exactly the same as in the EditEntry command.


Command: DeleteAllEntries

This command deletes all entries (in all subgroups).


Command: Export

This command exports the complete database. The format is specified by setting the "-Format" parameter (see names in KeePass' export dialog). The file to export to is specified using the "-OutFile" parameter. Usage example:

KPScript -c:Export "C:\KeePass\MyDb.kdbx" -pw:MyPw -Format:"KeePass XML (2.x)" -OutFile:TargetFile.xml


Command: Sync

This command synchronizes the database with another one. The other database path has to be specified using the "-File" command line parameter. Usage example:

KPScript -c:Sync -guikeyprompt "C:\Path\A.kdbx" -File:"C:\Path\B.kdbx"


Command: ChangeMasterKey

This command changes the master key of the database. The new key values are specified using the standard options prefixed with 'new', i.e. -newpw:, -newkeyfile: and -newuseraccount (all are optional). Usage example:

KPScript -c:ChangeMasterKey "C:\KeePass\MyDb.kdbx" -pw:MyPw -newpw:MyNewPw


Command: DetachBins

This command saves all entry attachments (into the directory of the database) and removes them from the database. Usage example:

KPScript -c:DetachBins -guikeyprompt "C:\KeePass\MyDb.kdbx"


Command: GenPw

Generates passwords. The number of passwords can be specified using the optional -count: parameter. A password generator profile can be specified using the optional -profile: parameter (the names of all available profiles can be found in the password generator dialog). Usage examples:

KPScript -c:GenPw
Generates one password using the default generator profile.

KPScript -c:GenPw -count:5 -profile:"128-Bit Hex Key (built-in)"
Generates five 128-bit hex passwords (when no translation is used).


Help  Console Character Encoding

If you observe garbled special characters in the output, please read the page Console Character Encoding.