Skip to content

Instantly share code, notes, and snippets.

@voice1
Last active February 23, 2024 23:12
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save voice1/58159602be2d9ef6cdb72b8c2224ca72 to your computer and use it in GitHub Desktop.
Save voice1/58159602be2d9ef6cdb72b8c2224ca72 to your computer and use it in GitHub Desktop.
# BitWarden tool to delete folders using bw CLI tool
# 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.
# NOTE: I use the utility sh (https://github.com/amoffat/sh) rather then os or subprocess, as I find it easier
import sh
import json
session_key = "Replace me with your session key"
# Sets this instance to use the provided session.
bw = sh.bw.bake('--session', session_key)
folders = bw('list', 'folders')
# The output provided is a string, luckily we can convert this to JSON
folders = json.loads(folders.stdout)
# Delete all the folders.. Add logic here if you want only a subset.
for folder in folders:
if folder.get('id'):
print(f"removing folder {folder['id']} {folder['name']}")
bw("delete", "folder", folder['id'])
@timskkim
Copy link

Thank you for the script! Is there an extra indent on line 24? Everything else worked great.

@eduncan911
Copy link

Forked and make a Delete All Collections version: https://gist.github.com/eduncan911/c0f4d789b87c3746a055779a57ff57e5

@worryboy
Copy link

worryboy commented Jan 5, 2023

if you down lod the cli on the mainpage it is currently blocked by issue bitwarden/clients#4040 on Version 2022.11.0
but works on https://github.com/bitwarden/cli/releases // Version 1.22.1

dosent work on windows see https://gist.github.com/KingWaffleIII/f346d737cc9445d938612c93daca7dd5 using subprocess

@voice1
Copy link
Author

voice1 commented Feb 23, 2024

I had forgotten about this and honestly wasn't paying attention. Glad it's useful to others.

Thank you for the script! Is there an extra indent on line 24? Everything else worked great.
@timskkim You are correct, I updated it. Believe it was a formatting issue due to copy and pasting of a gist.

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