Sort Vault Items by Revision Date Using the CLI

@Bill_Morgan Welcome to the forum, and thank you for this valuable contribution!

Based on your suggestion, I have come up with the following PowerShell script to find the oldest passwords in one’s vault:

param ($n=10)
$x =  .\bw list items
$y = $x | ConvertFrom-Json
$z = $y | Select-Object -ExpandProperty login -Property name
$z | Sort-Object -Property passwordRevisionDate | Select-Object -Property name,passwordRevisionDate -First $n

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! :sweat_smile:
    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):

(.\bw list items | ConvertFrom-Json) | Select-Object -ExpandProperty login -Property name | Sort-Object -Property passwordRevisionDate | Select-Object -Property name,passwordRevisionDate -First 10

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).

1 Like