diff --git a/backupBitwarden.ps1 b/backupBitwarden.ps1 index 1233cc8..659294d 100644 --- a/backupBitwarden.ps1 +++ b/backupBitwarden.ps1 @@ -18,14 +18,34 @@ if ($sessionKey -eq $null) { #convertfrom-json $(bw list organizations --session $sessionKey) Write-Host "Exporting vault to both CSV and JSON files." +Write-Verbose "Exporting vault to CSV." bw export $password --output "$PSScriptRoot\Bitwarden User $username Export $dateTime.csv" --format csv --session $sessionKey +Write-Verbose "Exporting vault to JSON." bw export $password --output "$PSScriptRoot\Bitwarden User $username Export $dateTime.json" --format json --session $sessionKey Write-Host "Looking for Organizations..." $organizations = $(convertfrom-json $(bw list organizations --session $sessionKey)) Write-Host "Found $(($organizations | measure).count) Organiztaions." +$organizations | foreach { + Write-Host "Exporting organization $($_.name) vault to both CSV and JSON files." + Write-Verbose "Exporting organization vault to CSV." + bw export $password --organizationid $_.id --output "$PSScriptRoot\Bitwarden Organization $($_.name) Export $dateTime.csv" --format csv --session $sessionKey + Write-Verbose "Exporting organization vault to JSON." + bw export $password --organizationid $_.id --output "$PSScriptRoot\Bitwarden Organization $($_.name) Export $dateTime.json" --format json --session $sessionKey +} -# (convertfrom-json $(bw list items --session $sessionKey)) | where attachments -# $itemsWithAttachments | % { $folder=$_.name; $itemID=$_.id; $_.attachments | % { bw get attachment $_.id --itemid $itemID --output "C:\Users\jgaunt\3D Objects\Bitwarden\$folder\$_.fileName" --session $sessionKey; sleep -Milliseconds 500 } } -# bw get attachment $attachmentID --itemid $itemID --output $file --session $sessionKey \ No newline at end of file +Write-Host "Looking for items with attachments..." +$itemsWithAttachments = $((ConverFro-Json $(bw list items --session $sessionKey)) | Where-Object attachments) +Write-Host "Found $(($itemsWithAttachments | measure).count) items with attachments." +Write-Host "Downloading attachments..." +$itemsWithAttachments | foreach { + Write-Verbose "Working on item $($_.name)." + $folder="$PSScriptRoot\$($_.name)" + $itemID=$_.id + $_.attachments | foreach { + Write-Verbose "Downloading attachment $($_.id) with name $($_.fileName) to $folder." + bw get attachment $_.id --itemid $itemID --output "$folder\$($_.fileName)" --session $sessionKey + sleep -Milliseconds 500 + } +} \ No newline at end of file