PowerShell/scripts/open-URL.ps1

34 lines
737 B
PowerShell
Raw Normal View History

2024-05-29 18:13:34 +02:00
<#
.SYNOPSIS
2024-06-17 12:20:02 +02:00
Opens an URL in the default browser
2024-05-29 18:13:34 +02:00
.DESCRIPTION
2024-06-17 12:20:02 +02:00
This PowerShell script launches a new tab in the default Web browser with the given URL.
2024-05-29 18:13:34 +02:00
.PARAMETER URL
Specifies the URL
2024-06-18 09:19:46 +02:00
.PARAMETER text
Specifies the text to write to the console
2024-05-29 18:13:34 +02:00
.EXAMPLE
2024-06-17 12:20:02 +02:00
PS> ./open-URL.ps1 https://cnn.com
2024-05-29 18:13:34 +02:00
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
2024-06-18 09:19:46 +02:00
param([string]$URL = "", [string]$text = "")
2024-05-29 18:13:34 +02:00
try {
2024-06-17 12:20:02 +02:00
if ($URL -eq "") { $URL = Read-Host "Enter the URL" }
2024-06-18 09:19:46 +02:00
if ($text -ne "") {
Write-Host $text -noNewline
Write-Host $URL -foregroundColor blue
}
2024-05-29 18:13:34 +02:00
Start-Process $URL
2024-06-18 09:19:46 +02:00
2024-05-29 18:13:34 +02:00
exit 0 # success
} catch {
2024-06-17 12:20:02 +02:00
"⚠️ Error: $($Error[0]) (script line $($_.InvocationInfo.ScriptLineNumber))"
2024-05-29 18:13:34 +02:00
exit 1
}