Skip to content

Instantly share code, notes, and snippets.

@eugrus
Created November 21, 2024 14:39
Show Gist options
  • Save eugrus/2588ff8df6c32b5546524a384a13799f to your computer and use it in GitHub Desktop.
Save eugrus/2588ff8df6c32b5546524a384a13799f to your computer and use it in GitHub Desktop.
Open each URL from a string of arguments in browser.
# Ensure an argument is passed
if ($args.Count -eq 0) {
Write-Host "Usage: OpenURLs.ps1 '<url1> <url2> ...'"
exit
}
# Concatenate all arguments to handle multiple strings
$inputString = $args -join ' '
# Split the string into individual URLs (space-separated)
$urls = $inputString -split '\s+'
# Loop through each URL and open it in the default browser
foreach ($url in $urls) {
if ($url -match '^https?://') {
Start-Process $url
} else {
Write-Host "Invalid URL skipped: $url"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment