Skip to content

Instantly share code, notes, and snippets.

@LuanRoger
Created February 22, 2022 19:05
Show Gist options
  • Save LuanRoger/bdb9a50a86dcf805be10abd4f3e3282a to your computer and use it in GitHub Desktop.
Save LuanRoger/bdb9a50a86dcf805be10abd4f3e3282a to your computer and use it in GitHub Desktop.
Search things on Google and access sites on the web.
<#
.SYNOPSIS
Search things on web.
.DESCRIPTION
Search things on Google and access sites on the web.
.PARAMETER Site
Specifies that will be a website
.PARAMETER SearchEngine
Specifies search engine
.PARAMETER Info
Show info about the script
.PARAMETER Help
Show instructions about how to use the script
.EXAMPLE
PS> power_google.ps1 "How big is the Eiffel Tower"
.EXAMPLE
PS> power_google.ps1 "How big is the Eiffel Tower" -SearchEngine bing
.EXAMPLE
PS> power_google.ps1 "github.com/LuanRoger" -Site
#>
param (
[Parameter(Position=0)][string]$SearchTerm,
[Parameter(Mandatory=$false)][switch]$Site = $false,
[Parameter(Mandatory=$false)]
[string]
[ValidateSet("gogle", "bing")]
$SearchEngine = "google",
[Parameter(Mandatory=$false)][switch]$Info = $false,
[Parameter(Mandatory=$false)][switch]$Help = $false
)
function LaunchUrl {
param (
$Url
)
Start-Process "https://$Url"
}
function SearchTerm {
param ($Term, $Engine)
$url = switch ( $Engine ) {
"google" { "www.google.com/search?q=$Term" }
"bing" { "www.bing.com/search?q=$Term" }
Default { "www.google.com/search?q=$Term" } #Google
}
Start-Process $url
}
function ScriptHelp {
Get-Help $PSCommandPath -Detailed
exit
}
function ShowInfo {
Write-Host "Power Google Script"
Write-Host "Follow me on GitHub: https://github.com/LuanRoger"
Write-Host "Script version: v1.0"
exit
}
if($Help) {
ScriptHelp
}
if($Info) {
ShowInfo
}
if($Site) {
LaunchUrl $SearchTerm
}
else {
SearchTerm $SearchTerm $SearchEngine
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment