Files
bitwardenbackup/backupBitwarden.ps1

26 lines
1.4 KiB
PowerShell

# get the date/time for the back filename
$dateTime = get-date -format ("yyyyMMdd-HHmmss")
$env:Path += ";$PSScriptRoot\lib;$PSScriptRoot\lib\gpg\bin"
bw config server https://bitwarden.johnhgaunt.com
if ($sessionKey -eq $null) {
$username = "jgaunt@johnhgaunt.com"
$password = Read-Host -assecurestring "Please enter your bitwarden password: "
$password = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($password))
$code = Read-Host "Please enter your 2fa code: "
$sessionKey = $(bw login $username $password --method 0 --code $code --raw)
}
#convertfrom-json $(bw list organizations --session $sessionKey)
bw export $password --output "C:\users\jgaunt\3D Objects\Bitwarden User $username Export $dateTime.csv" --format csv --session $sessionKey
bw export $password --output "C:\users\jgaunt\3D Objects\Bitwarden User $username Export $dateTime.json" --format json --session $sessionKey
$organizations = $(convertfrom-json $(bw list organizations))
# I shouldn't need portwarden anymore since I will just use bw and loop through the items with attachments
# (convertfrom-json $(bw list items)) | where attachments
# $itemsWithAttachments | % { $folder=$_.name; $itemID=$_.id; $_.attachments | % { bw get attachment $_.id --itemid $itemID --output "C:\Users\jgaunt\3D Objects\Bitwarden\$folder\$_.fileName" } }
# bw get attachment $attachmentID --itemid $itemID --output $file