# Simple Bitwarden .env Sync for Windows # Run with: powershell -ExecutionPolicy Bypass -File sync-env.ps1 Write-Host "=== Bitwarden .env Sync ===" -ForegroundColor Cyan # Check if bw is installed if (!(Get-Command bw -ErrorAction SilentlyContinue)) { Write-Host "Error: Bitwarden CLI (bw) is not installed" -ForegroundColor Red Write-Host "Install it from: https://bitwarden.com/help/cli/" exit 1 } # Check status $status = bw status | ConvertFrom-Json if ($status.status -eq "unauthenticated") { Write-Host "Please login to Bitwarden:" bw login $status = bw status | ConvertFrom-Json } # Unlock if needed if ($status.status -eq "locked") { Write-Host "Unlocking vault..." $env:BW_SESSION = bw unlock --raw if ($LASTEXITCODE -ne 0) { Write-Host "Error: Failed to unlock vault" -ForegroundColor Red exit 1 } } # Sync Write-Host "Syncing with Bitwarden..." bw sync | Out-Null # CHANGE THIS to your Bitwarden item name $itemName = "portfolio-env" Write-Host "Fetching environment variables..." # Get item $item = bw get item $itemName 2>$null | ConvertFrom-Json if (!$item) { Write-Host "Error: Could not find item '$itemName' in Bitwarden" -ForegroundColor Red Write-Host "Make sure you have an item with this exact name in your vault" exit 1 } # Get notes $notes = $item.notes if (!$notes) { Write-Host "Error: No notes found in item '$itemName'" -ForegroundColor Red Write-Host "Add your environment variables to the notes field" exit 1 } # Create .env file $notes | Out-File -FilePath ".env" -Encoding UTF8 -NoNewline Write-Host "✓ Created .env file successfully!" -ForegroundColor Green