Skip to content

Commit

Permalink
Included code to download the BW CLI application for you if the scrip…
Browse files Browse the repository at this point in the history
…t doesn't detect one in the current environment.
  • Loading branch information
trparky committed Dec 20, 2023
1 parent 1e516fa commit 06b10fa
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion bw_export.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,37 @@ try {
# ====================================================

Write-Host -ForegroundColor Green "========================================================================================"
Write-Host -ForegroundColor Green "== Bitwarden Vault Export Script v1.15 =="
Write-Host -ForegroundColor Green "== Bitwarden Vault Export Script v1.16 =="
Write-Host -ForegroundColor Green "== Originally created by David H, converted to a Powershell Script by Thomas Parkison =="
Write-Host -ForegroundColor Green "========================================================================================"
Write-Host ""

if ($IsWindows) { $bwCliBinName = (Join-Path (Get-Location) "bw.exe") }
else { $bwCliBinName = (Join-Path (Get-Location) "bw") }

if (!(Test-Path -Path $bwCliBinName)) {
Write-Host "Bitwarden CLI application not found, downloading... Please Wait." -NoNewLine
$zipFilePath = (Join-Path (Get-Location) "bw.zip")

if ($IsWindows) { Invoke-WebRequest "https://vault.bitwarden.com/download/?app=cli&platform=windows" -OutFile $zipFilePath }
elseif ($IsLinux) { Invoke-WebRequest "https://vault.bitwarden.com/download/?app=cli&platform=linux" -OutFile $zipFilePath }
elseif ($IsMacOS) { Invoke-WebRequest "https://vault.bitwarden.com/download/?app=cli&platform=macos" -OutFile $zipFilePath }

Expand-Archive -Path $zipFilePath

if ($IsLinux || $IsMacOS) {
Move-Item (Join-Path (Get-Location) "bw" "bw") (Join-Path (Get-Location) "bw.tmp")
Remove-Item -Force (Join-Path (Get-Location) "bw")
Move-Item (Join-Path (Get-Location) "bw.tmp") (Join-Path (Get-Location) "bw")
chmod 755 (Join-Path (Get-Location) "bw")
}

Remove-Item $zipFilePath

Write-Host " Done."
Write-Host ""
}

# Prompt user for their Bitwarden username
$userEmail = Read-Host "Enter your Bitwarden Username"

Expand Down

0 comments on commit 06b10fa

Please sign in to comment.