div class='cap-left'/>

Do-It-Your-Self Demo - PSKeePass

Monday, December 7, 2015


This post will provide a do-it-your-self demo in order to understand the basics and potential of the PSKeePass PowerShell module. Completion time is about 10 minutes.

What will you learn?

After completing the demo you will have a basic understanding on how to use the module and how it can be applied.

What are we going do to?

You will follow the basic steps of importing the module and create a new KeePass database, followed by adding an entry in to that database. Then we are going to create a PowerShell script (function) that uses the Get-KeePassEntry cmdlet to get the credential you created and opens a terminal server session.


Follow the installation instructions on the PsKeePass project page.


Depending on your operating system, your PowerShell version may vary, For Windows 2008R2 it is PowerShell 2.0, Windows 10 has PowerShell 5.0. I am assuming the latter. Please be aware that PowerShell 2.0 has some limitations by design (e.g. TAB completion), please check the  PsKeePass project page for further details. During the instructions represents the server to connect to, please change it to the appropriate hostname for you without the parenthesis. Path will be represented as "D:\Demo\", please change these to valid paths appropriate for you.

Copy ​Invoke-Mstsc.ps1

You can find the script here and copy it to the folder of your choice which is in my case D:\Demo. You might notice from reading the script source that I store the provided credential in the Windows Credential Manager. This is required because the latest MSTSC versions no longer have the ability to add a credential from the command line.


Follow the instruction below to complete the demo. Are you ready???!

Step 1: 

Open PowerShell console and import the module. The -Verbose option is optional, but it helps understanding what is happening in the background.

Step 2: 

Create a new KeePass database using your current account as composite key.

Step 3: 

Add a new database entry (credential) with the title "Demo User", username "Administrator" and password "lightyear" in a group named "Sample Group" and change the entry icon to Windows symbol.

Step 4:  

In order to initiate the remote desktop session we have to create a PowerShell PSCredential object using the newly created entry. This credential object is than stored in the variable $cred. For demonstration purposes I have added the parameter -Group, since this database only has one entry with the name "Administrator" this parameter is not required.

Step 6: 

Once we have the credentials stored, we no longer need the KeePass database to be open. So let's close it.

Step 7: 

Finally we can start initiate the remote desktop session. Notice the dot sourcing of the function.

Final Notes

Now that you have a basic understanding how to use the PSKeePass module, it is up to you to think of great applications!

No comments :

Post a Comment