Skip to content

Instantly share code, notes, and snippets.

@Swimburger
Created August 7, 2022 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Swimburger/0ba4c3149b58102d16c7224f496d5ff0 to your computer and use it in GitHub Desktop.
Save Swimburger/0ba4c3149b58102d16c7224f496d5ff0 to your computer and use it in GitHub Desktop.
Scans for duplicates and removes them using the Bitwarden CLI
$Items = bw list items | ConvertFrom-Json
Function Compare-Values($Name, $Item1, $Item2) {
if ($Item1 -eq $Item2) {
Write-Host "✅ $($Name): $Item1 =="
return $true
}
else {
Write-Host "⚠️ $($Name): $Item1 <> $Item2";
return $false
}
}
$Items `
| Where-Object { $_.login.uris -ne $null } `
| Group-Object -Property { $_.login.uris[0].uri } `
| Where-Object { $_.Count -gt 1 } `
| ForEach-Object {
$Item1 = $_.Group[0]
$Item2 = $_.Group[1]
$Uris1 = $Item1.login.uris.uri | Sort-Object | Join-String -Separator ', '
$Uris2 = $Item2.login.uris.uri | Sort-Object | Join-String -Separator ', '
$NameEquals = Compare-Values "Name" $Item1.name $Item2.name
$UsernameEquals = Compare-Values "Username" $Item1.login.username $Item2.login.username
$PasswordEquals = Compare-Values "Password" $Item1.login.password $Item2.login.password
$TotpEquals = Compare-Values "Totp" $Item1.login.totp $Item2.login.totp
$UrisEquals = Compare-Values "Uris" $Uris1 $Uris2
$NotesEquals = Compare-Values "Notes" $Item1.notes $Item2.notes
If (
$NameEquals -and
$UsernameEquals -and
$PasswordEquals -and
$TotpEquals -and
$UrisEquals -and
$NotesEquals
) {
bw delete item $($Item1.id)
Write-Host "$($Item1.id) deleted"
}
Else {
While ($True) {
$Response = Read-Host -Prompt "Delete A or B or skip? [A]";
If ($Response -eq "Skip") {
Write-Host "Skipped"
Break;
}
ElseIf ($Response -eq "" -or $Response -eq "A") {
bw delete item $($Item1.id)
Write-Host "$($Item1.id) deleted"
Break;
}
ElseIf ($Response -eq "B") {
bw delete item $($Item2.id)
Write-Host "$($Item2.id) deleted"
Break;
}
Else {
Continue;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment