Skip to content

Instantly share code, notes, and snippets.

@KingWaffleIII
Created November 10, 2021 20:45
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KingWaffleIII/f346d737cc9445d938612c93daca7dd5 to your computer and use it in GitHub Desktop.
Save KingWaffleIII/f346d737cc9445d938612c93daca7dd5 to your computer and use it in GitHub Desktop.
Bitwarden Collections Remover
# BitWarden tool to delete collections using bw CLI tool
# forked from: https://gist.github.com/eduncan911/c0f4d789b87c3746a055779a57ff57e5
# uses subprocess to run bw commands rather than sh which is Linux only
# You must install the bitwarden CLI tool (https://bitwarden.com/help/article/cli/#download-and-install)
# Create your session as per the instructions on the download page.
# You can replace your session key and use the following to process the results.
# place this script in the same dir as the bw executable
import subprocess
import json
# session_key = "<REPLACE-WITH-YOUR-CLI-SESSION-KEY>"
session_key = input("Enter your session key: ")
# Base command to run bw commands
bw = [".\\bw.exe", "--session", session_key]
# get collections from cli
collections = subprocess.run(bw + ["list", "collections"], stdout=subprocess.PIPE)
# The output provided is a string, luckily we can convert this to JSON
collections = json.loads(collections.stdout.decode("utf-8"))
# Delete all the collections.. Add logic here if you want only a subset.
for collection in collections:
if collection.get('id'):
print(f"Removing collection: {collection['id']} {collection['name']} {collection['organizationId']}.")
subprocess.run(bw + ["delete", "org-collection", collection['id'], "--organizationid", collection["organizationId"]])
print('Collections removed :)')
@eduncan911
Copy link

Nice

@KingWaffleIII
Copy link
Author

Nice

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment