Last active
May 28, 2024 17:21
-
-
Save KingWaffleIII/f346d737cc9445d938612c93daca7dd5 to your computer and use it in GitHub Desktop.
BitWarden tool to delete collections using bw CLI tool
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 :)') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice