Created
November 21, 2024 14:39
-
-
Save eugrus/2588ff8df6c32b5546524a384a13799f to your computer and use it in GitHub Desktop.
Open each URL from a string of arguments in browser.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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