Edit: The above post was revised on 2023-01-30, to make corrections to the PowerShell script. In addition, alternatives to the above PowerShell expression have been posted below (here and here). [Edit by @grb]
For the benefit of those users who new to these tools, the jq tool can be downloaded here, and instructions for downloading and installing the Bitwarden CLI are available here.
The PowerShell method does not require installation of the jq tool, only the CLI. To open a Windows PowerShell console in Windows 10, just right-click the Start Menu button (Windows icon) and select “Windows PowerShell”. Instructions for accessing PowerShell in Windows 11 are available here.
I can use some help with the PowerShell option. Ideally, I can create a script to run and output the sort in order to track a large number of password changes.
In PS, when I execute the commands in a single line–I stringed the command together to look like this: .\bw list items | ConvertFrom-Json | Select-Object -Property Name, RevisionDate | Sort-Object -Property RevisionDate -Descending | Select-Object -First 10.
After entering the mater pw, I got a blank Name and RevisionDate, but no entries. Any ideas why?
I’m looking for a easy solution to run this as I make changes. I’d appreciate any help.
I do see all the vault contents scroll by in JSON format when I do “bw list items”.
When I use “.\bw list items | ConvertFrom-Json | Select-Object -Property Name, RevisionDate | Sort-Object -Property RevisionDate -Descending | Select-Object -First 10”, I get: “Name RevisionDate” but nothing underneath it.
So the command bw list items works, but the command that starts with .\bw list items doesn’t work. How about removing the first two characters (.\) from the second command?
Sorry, I should have been more clear, in PS, I always have to use .\ to run an executable. So in this case, the full command was “.\bw list items”. Otherwise, PS errors with “the term ‘…bw’ is not recognized”
OK, I understand. When debugging code on a forum, it is best to share the expressions verbatim. Even better to enclose the code snippets using the “preformatted text” format (click on </> button in editor, or type ` at the start and end of the source code snippets).
So, if I understand correctly, the following expression works: .\bw list items
.\bw list items | ConvertFrom-Json | Select-Object -First 1
What column names to you see at the top? Please copy & paste verbatim from the PowerShell output into the forum editor (and preferably enclose the pasted text by a pair of ` separators).
.\bw list items | ConvertFrom-Json | Select-Object -First 1
I see the list of my entire vault scroll by. It exceeds the buffer, so when I scroll up, I do not see the column names at the top, but the screenshot is a sample of what the entries look like:
OK, it’s a bit challenging for me to debug this, because I don’t have the CLI installed myself, so I can’t do my own testing. I did find a site that showed sample output of the bw list items command:
Using this, I am able to reproduce your results (i.e., it apparently doesn’t work).
I conclude that either the format of the output of the bw list items CLI command or the behavior of the ConvertFrom-Json PowerShell commandlet has changed since March, or perhaps @Chris_Magnuson proposed the above command sequence on the theory that it would work, but without actually testing it.
Hopefully, someone with more experience using the CLI (and/or PowerShell) can step in to debug this further.
Update (2023-01-30):
@snovvman The code originally proposed by @Chris_Magnuson can be fixed by inserting “.\” before the “bw” command, by using parentheses to enclose the expression “.\bw list items | ConvertFrom-Json”, and by removing the parameter “-Descending” from the sorting command. The top post has now been edited to incorporate these corrections. In addition, alternative PowerShell expressions have been proposed below (here and here).
Copy and paste the above into a text file, renaming it oldest.ps1 and save it in a folder on the PowerShell path. Then type the following to list the 25 oldest passwords (for example):
.\oldest 25
Just typing .\oldest without specifying a number should list the oldest 10 passwords by default (if you wish, you can change this default behavior by modifying the number shown in the first line of the script).
Alternatively (e.g., if you are having with the path or with permissions for running scripts), just copy and execute each line of the above code individually, except that the first line should just be $n = 25 (or whatever number of passwords you want to list) without the “param” keyword or the parentheses.
Caveats:
I have tested this only by hardcoding the sample output of .\bw list items that I had found above, as I don’t have the Bitwarden CLI client installed.
I know very little about PowerShell scripting (and I learned something new from @Bill_Morgan today!), so the code above may be inelegant. However, I am 90% sure it will work!
Please let me know if this works for you, or if you have any problems with this script.
Edit:
Inspired by this recent post by @tijama, I was able to convert my script above to a one-liner which can be copy-pasted directly into the PowerShell terminal (without creating a script):
The number 10 at the end of the line can be modified (it represents the number of items that will be displayed), or you can omit the -First 10 altogether to list all vault items (sorted in order of the most recent password revision).
Thank you for this! I had recently converted from LastPass and like other’s wanted to be able to keep track of which passwords I had changed and which I had not. Two observations, entries that had been converted from lastpass and not edited do not have a date. This makes sense because there has been no revision. Also, I had errors at the beginning of the output, these seemed to be from secure notes (not login’s).