2024-11-08 12:38:20 +01:00
|
|
|
The *open-URL.ps1* Script
|
|
|
|
===========================
|
2024-08-15 09:51:46 +02:00
|
|
|
|
|
|
|
This PowerShell script launches a new tab in the default Web browser with the given URL.
|
|
|
|
|
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
```powershell
|
2024-11-08 12:35:11 +01:00
|
|
|
/home/markus/Repos/PowerShell/scripts/open-URL.ps1 [[-URL] <String>] [[-text] <String>] [<CommonParameters>]
|
2024-08-15 09:51:46 +02:00
|
|
|
|
|
|
|
-URL <String>
|
|
|
|
Specifies the URL
|
|
|
|
|
|
|
|
Required? false
|
|
|
|
Position? 1
|
|
|
|
Default value
|
|
|
|
Accept pipeline input? false
|
|
|
|
Accept wildcard characters? false
|
|
|
|
|
|
|
|
-text <String>
|
|
|
|
Specifies the text to write to the console
|
|
|
|
|
|
|
|
Required? false
|
|
|
|
Position? 2
|
|
|
|
Default value
|
|
|
|
Accept pipeline input? false
|
|
|
|
Accept wildcard characters? false
|
|
|
|
|
|
|
|
[<CommonParameters>]
|
|
|
|
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
|
|
|
|
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
|
|
|
|
```
|
|
|
|
|
|
|
|
Example
|
|
|
|
-------
|
|
|
|
```powershell
|
|
|
|
PS> ./open-URL.ps1 https://cnn.com
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
Notes
|
|
|
|
-----
|
|
|
|
Author: Markus Fleschutz | License: CC0
|
|
|
|
|
|
|
|
Related Links
|
|
|
|
-------------
|
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
|
|
|
|
Script Content
|
|
|
|
--------------
|
|
|
|
```powershell
|
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
|
|
Opens an URL in the default browser
|
|
|
|
.DESCRIPTION
|
|
|
|
This PowerShell script launches a new tab in the default Web browser with the given URL.
|
|
|
|
.PARAMETER URL
|
|
|
|
Specifies the URL
|
|
|
|
.PARAMETER text
|
|
|
|
Specifies the text to write to the console
|
|
|
|
.EXAMPLE
|
|
|
|
PS> ./open-URL.ps1 https://cnn.com
|
|
|
|
.LINK
|
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
.NOTES
|
|
|
|
Author: Markus Fleschutz | License: CC0
|
|
|
|
#>
|
|
|
|
|
|
|
|
param([string]$URL = "", [string]$text = "")
|
|
|
|
|
|
|
|
try {
|
|
|
|
if ($URL -eq "") { $URL = Read-Host "Enter the URL" }
|
|
|
|
|
|
|
|
if ($text -ne "") {
|
|
|
|
Write-Host $text -noNewline
|
|
|
|
Write-Host $URL -foregroundColor blue
|
|
|
|
}
|
2024-11-08 12:35:11 +01:00
|
|
|
if ($IsLinux) {
|
|
|
|
} else {
|
|
|
|
Start-Process $URL
|
|
|
|
}
|
2024-08-15 09:51:46 +02:00
|
|
|
exit 0 # success
|
|
|
|
} catch {
|
|
|
|
"⚠️ Error: $($Error[0]) (script line $($_.InvocationInfo.ScriptLineNumber))"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2024-11-08 12:38:20 +01:00
|
|
|
*(generated by convert-ps2md.ps1 using the comment-based help of open-URL.ps1 as of 11/08/2024 12:37:55)*
|