Last active
October 31, 2025 13:35
-
-
Save tigrouind/a516b737c49bdaae32771015995eeb1f to your computer and use it in GitHub Desktop.
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
| /* | |
| what it does: | |
| - associate vault entries to the right subfolder. | |
| - set uri, notes and otp. | |
| - cleanup of uneeded custom fields. | |
| Instructions: | |
| - export Buttercup vault to CSV | |
| - do a backup/export of your Bitwarden vault (in case it went wrong) | |
| - import into Bitwarden | |
| - run code below. needed: | |
| https://github.com/OceanAirdrop/Bitwarden-Vault-CLI-API | |
| Bitwarden CLI executable to be in same folder as project | |
| */ | |
| string? GetField(Item item, string key) | |
| { | |
| return item.fields.Where(x => string.Equals(x.name, key, StringComparison.InvariantCultureIgnoreCase)) | |
| .Select(x => x.value) | |
| .FirstOrDefault(); | |
| } | |
| var toRemove = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase) | |
| { | |
| "!group_id", | |
| "!type", | |
| "title", | |
| "id", | |
| "note", | |
| "url", | |
| "username", | |
| "password", | |
| "otp" | |
| }; | |
| var items = bitwarden.ListItems(); | |
| foreach (var item in items.Where(x => x.name != "--")) | |
| { | |
| //associate to right subfolder | |
| if (item.folderId == null) | |
| { | |
| var groupId = GetField(item, "!group_id"); | |
| item.folderId = items.First(x => x.name == "--" && GetField(x, "!group_id") == groupId).folderId; | |
| } | |
| //set uri | |
| if (!item.login.uris.Any()) | |
| { | |
| item.login.uris.Add(new BitwardenVaultCLI_API.Model.Uri() { uri = GetField(item, "url")! }); | |
| } | |
| //set notes | |
| var note = GetField(item, "note"); | |
| if (note != null) | |
| { | |
| item.notes = note; | |
| } | |
| //set notes | |
| var otp = GetField(item, "otp"); | |
| if (otp != null) | |
| { | |
| item.login.otp = otp; | |
| } | |
| //cleanup | |
| item.fields.RemoveAll(x => toRemove.Contains(x.name)); | |
| Console.WriteLine(item.name); | |
| bitwarden.EditItem(item); | |
| } | |
| //remove all "--" entries | |
| foreach (var item in items.Where(x => x.name == "--")) | |
| { | |
| Console.WriteLine(item.name); | |
| bitwarden.DeleteItem(item.id); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment