PowerShell/scripts/open-URL.ps1

26 lines
561 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
.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-17 12:20:02 +02:00
param([string]$URL = "")
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-05-29 18:13:34 +02:00
Start-Process $URL
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
}