param( [string]$to = "", [string]$pt = "", [switch]$ur, [switch]$hp ) function Show-Help { @" sf-web-open.ps1 — PowerShell wrapper for ``sf org open`` USAGE: sf-web-open.ps1 [-to ] [-pt ] [-ur] sf-web-open.ps1 -hp OPTIONS: -to Target org alias or username to pass as --target-org (recommended) -pt Path - relative path to open inside the org (e.g., "/lightning/setup/SetupOneHome/home") -ur URL-only: print the URL instead of opening a browser (passes --url-only) -hp Help - show this help EXAMPLES: 1) Open a specific org (default home): sf-web-open.ps1 -to "DEMO-ORG" 2) Open Setup Home of a target org: sf-web-open.ps1 -to "NUSHUB-DR2" -pt "/lightning/setup/SetupOneHome/home" 3) Get just the URL for scripting: sf-web-open.ps1 -to "NUSHUB-DR2" -ur "@ } # Show help if requested if ($hp) { Show-Help exit 0 } # If no parameters provided, show help and examples if ($to -eq "" -and $pt -eq "" -and -not $ur) { Show-Help exit 0 } # Silent environment check - verify SF CLI is available try { Get-Command sf -ErrorAction Stop | Out-Null } catch { Write-Host "❌ Salesforce CLI (sf) not found!" -ForegroundColor Red Write-Host "" Write-Host "Running environment check to help you get started..." Write-Host "" # Try to find and run sf-check.ps1 in the same directory as this script $scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path $sfCheckPath = Join-Path $scriptDir "sf-check.ps1" if (Test-Path $sfCheckPath) { & $sfCheckPath } elseif (Get-Command sf-check.ps1 -ErrorAction SilentlyContinue) { sf-check.ps1 } else { Write-Host "sf-check.ps1 not found. Please install the Salesforce CLI from:" Write-Host "https://developer.salesforce.com/tools/sfdxcli" } exit 1 } # Build the command array $cmd = @("sf", "org", "open") # Add target org if specified if ($to -ne "") { $cmd += "--target-org" $cmd += $to } # Add path if specified if ($pt -ne "") { $cmd += "--path" $cmd += $pt } # Add URL-only flag if specified if ($ur) { $cmd += "--url-only" } # Display the command being executed Write-Host ">>> Running: $($cmd -join ' ')" -ForegroundColor Yellow # Execute the command try { & $cmd[0] $cmd[1..($cmd.Length-1)] exit $LASTEXITCODE } catch { Write-Error "Failed to execute sf command: $_" exit 1 }