Sort Vault Items by Revision Date Using the CLI

I think @rts is describing errors using the sorting algorithms for vault items that are already imported. I believe it would be possible to modify the PowerShell expressions to include a filter of the form | Where-Object {$_.type -eq 1} |, but as my knowledge of PowerShell is rudimentary, I won’t be able to write a complete expression without experimenting (which I don’t currently have time for).

As mentioned by @grb , filtering on the type of item before selecting the ‘login’ property, should get rid of the errors. The following should work:

.\bw list items | ConvertFrom-Json | Where-Object { $_.type -eq 1 } | Select-Object -ExpandProperty login -Property name | Where-Object { $null -ne $_.passwordRevisionDate } | Sort-Object -Property passwordRevisionDate | Select-Object -Property name, passwordRevisionDate

This should display only items which contains a revision date.

Hope this helps
Cliff

Thank you @cliff, I gave your code a try but got the following error:

Select-Object : Property "login" cannot be found.
At line:1 char:170
+ ... e -eq 1 } | Select-Object -ExpandProperty login -Property name | Wher ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (               ...               :PSObject) [Select-Object], PSArgumen
   tException
    + FullyQualifiedErrorId : ExpandPropertyNotFound,Microsoft.PowerShell.Commands.SelectObjectCommand

Edited. This is the same error that I got before each entry that was not a log in. Here I just got it once but with no other output.

Edited again. Got it to work, I had to add parenthesis around (.\bw list items | ConvertFrom-Json).
This doesn’t quite work for what I need as it will only show those logins that have been changed. I took out your second where clause and ended up with this:

(.\bw list items | ConvertFrom-Json) | Where-Object { $_.type -eq 1 } | Select-Object -ExpandProperty login -Property name | Sort-Object -Property passwordRevisionDate | Select-Object -Property name, passwordRevisionDate

This gets rid of the errors and shows all logins. Now I just need to figure out how to discern new logins I’ve added versus logins I haven’t changed yet. :thinking:

Thanks for your help!

Try this instead:

(.\bw list items | ConvertFrom-Json) | Where-Object { $_.type -eq 1 } | Select-Object -ExpandProperty login -Property name | Where-Object { $null -ne $_.passwordRevisionDate } | Sort-Object -Property passwordRevisionDate | Select-Object -Property name, passwordRevisionDate

@rts Glad you got it sorted out.

@rts Try to adapt the earlier versions of the PowerShell script, which don’t use the login.passwordRevisionDate property to sort, but instead use revisionDate. @Bill_Morgan’s idea of also outputting passwordHistory may help, as well. I had changed the sorting parameter to login.passwordRevisionDate because it should yield more specific results, but perhaps this is causing other problems when that field is null. I believe that even freshly imported items have a revisionDate value (corresponding to the date of import), but I could be remembering that incorrectly. Worth a try.

here’s an updated script… it will pull login data and sort by revisiondate. Look at passwordrevisiondate - if that’s not there, you haven’t updated it.

.\bw sync
$e = .\bw list items
$f = $e | ConvertFrom-Json
$g = $f | Select-Object -Property name, revisiondate, login
$depServ = $g | Select-Object -Property @{name=“PWD Rev Date”; expr={$_.login.passwordRevisionDate}}, name, RevisionDate
$depserv | select-object -Property name, revisiondate, “PWD Rev Date” | Sort-Object -Property RevisionDate, “PWD Rev Date” -Descending
$depserv | select-object -Property name, revisiondate, “PWD Rev Date” | Sort-Object -Property RevisionDate, “PWD Rev Date” -Descending | export-csv -path .\pwd.csv

Thanks @Bill_Morgan . Sorry, I couldn’t get this script to work. I don’t know much about powershell or json. Looks like I got this error for each entry:

Select-Object : The property cannot be processed because the property "uris" already exists.

@Bill_Morgan I’m good thanks. Although I didn’t get that last script to work. I went back to your original and it does what I need without any errors. Thanks.

OMg… I published the wrong script. I corrected it.

1 Like

perfect, thanks!