Skip to main content

Various Powershell Scripts

About 28 minPowershellVarious Powershell Scriptspowershellpwshwindowsscriptuseful-scriptmysql

Various Powershell Scripts 관련


add-memo.ps1

add-memo.ps1

Adds the given memo text to $HOME/Memos.csv.

This PowerShell script saves the given memo text to Memos.csv in your home folder.

Parameters
PS> ./add-memo.ps1 [[-text] <String>] [<CommonParameters>]

-text <String>
    Specifies the text to memorize
    
    Required?                    false
    Position?                    1
    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.

check-ipv4-address.ps1

check-ipv4-address.ps1

Checks the given IPv4 address for validity.

This PowerShell script checks the given IPv4 address for validity.

Parameters
PS> ./check-ipv4-address.ps1 [[-Address] <String>] [<CommonParameters>]

-Address <String>
    Specifies the IPv4 address to check
    
    Required?                    false
    Position?                    1
    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.

check-ipv6-address.ps1

check-ipv6-address.ps1

Checks the given IPv6 address for validity.

This PowerShell script checks the given IPv6 address for validity

Parameters
PS> ./check-ipv6-address.ps1 [[-Address] <String>] [<CommonParameters>]

-Address <String>
    Specifies the IPv6 address to check
    
    Required?                    false
    Position?                    1
    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.

check-mac-address.ps1

check-mac-address.ps1

Checks the given MAC address for validity.

This PowerShell script checks the given MAC address for validity Supported MAC address formats are:

  • 00:00:00:00:00:00 or
  • 00-00-00-00-00-00 or
  • 000000000000
Parameters
PS> ./check-mac-address.ps1 [[-MAC] <String>] [<CommonParameters>]

-MAC <String>
    Specifies the MAC address to check
    
    Required?                    false
    Position?                    1
    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.

check-subnet-mask.ps1

check-subnet-mask.ps1

Checks the given subnet mask for validity.

This PowerShell script checks the given subnet mask for validity.

Parameters
PS> ./check-subnet-mask.ps1 [[-address] <String>] [<CommonParameters>]

-address <String>
    Specifies the subnet mask to check
    
    Required?                    false
    Position?                    1
    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.

display-time.ps1

display-time.ps1

Displays the current time for 10 seconds by default.

This PowerShell script displays the current time (for 10 seconds by default)

Parameters
PS> ./display-time.ps1 [[-Seconds] <Int32>] [<CommonParameters>]

-Seconds <Int32>
    Specifies the number of seconds to display the time
    
    Required?                    false
    Position?                    1
    Default value                10
    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.

list-environment-variables.ps1

list-environment-variables.ps1

Lists all environment variables.

This PowerShell script lists all environment variables.

Parameters
PS> ./list-environment-variables.ps1 [<CommonParameters>]

[<CommonParameters>]
    This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, 
    WarningVariable, OutBuffer, PipelineVariable, and OutVariable.

list-emojis.ps1

list-emojis.ps1

Lists the emojis of Unicode 13.0.

This PowerShell script lists the emojis of Unicode 13.0 sorted by category.

Parameters
PS> ./list-emojis.ps1 [<CommonParameters>]

[<CommonParameters>]
    This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, 
    WarningVariable, OutBuffer, PipelineVariable, and OutVariable.

list-exchange-rates.ps1

list-exchange-rates.ps1

Lists the current exchange rates for the given currency.

This PowerShell script lists the current exchange rates for the given currency (USD per default).

Parameters
PS> ./list-exchange-rates.ps1 [[-currency] <String>] [<CommonParameters>]

-currency <String>
    Specifies the base currency
    
    Required?                    false
    Position?                    1
    Default value                USD
    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.

list-memos.ps1

list-memos.ps1

Lists the memos at $HOME/Memos.csv.

This PowerShell script lists all memo entries in Memos.csv in your home folder.

Parameters
PS> ./list-memos.ps1 [<CommonParameters>]

[<CommonParameters>]
    This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, 
    WarningVariable, OutBuffer, PipelineVariable, and OutVariable.

list-mysql-tables.ps1

list-mysql-tables.ps1

Lists the MySQL server tables.

This PowerShell script lists all tables of the given MySQL database.

Parameters
PS> ./list-mysql-tables.ps1 [-server] <Object> [-database] <Object> [-dbuser] <Object> [-dbpass] <Object> [<CommonParameters>]

-server <Object>
    
    Required?                    true
    Position?                    1
    Default value                
    Accept pipeline input?       false
    Accept wildcard characters?  false

-database <Object>
    
    Required?                    true
    Position?                    2
    Default value                
    Accept pipeline input?       false
    Accept wildcard characters?  false

-dbuser <Object>
    
    Required?                    true
    Position?                    3
    Default value                
    Accept pipeline input?       false
    Accept wildcard characters?  false

-dbpass <Object>
    
    Required?                    true
    Position?                    4
    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.

list-news.ps1

list-news.ps1

Lists the latest news.

This PowerShell script lists the latest news by using RSS (Really Simple Syndication) feeds.

Parameters
PS> ./list-news.ps1 [[-RSS_URL] <String>] [[-maxLines] <Int32>] [[-speed] <Int32>] [<CommonParameters>]

-RSS_URL <String>
    Specifies the URL to the RSS feed (Yahoo News by default)
    
    Required?                    false
    Position?                    1
    Default value                https://yahoo.com/news/rss/world
    Accept pipeline input?       false
    Accept wildcard characters?  false

-maxLines <Int32>
    Specifies the maximum number of lines to list (24 by default)
    
    Required?                    false
    Position?                    2
    Default value                24
    Accept pipeline input?       false
    Accept wildcard characters?  false

-speed <Int32>
    Specifies the speed to write the text (10 ms by default)
    
    Required?                    false
    Position?                    3
    Default value                10
    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.

list-os-releases.ps1

list-os-releases.ps1

Lists operating system releases and download URL.

This PowerShell script lists OS releases and download URL.

Parameters
PS> ./list-os-releases.ps1 [<CommonParameters>]

[<CommonParameters>]
    This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, 
    WarningVariable, OutBuffer, PipelineVariable, and OutVariable.

list-os-updates.ps1

list-os-updates.ps1

Lists operating system updates.

This PowerShell script lists the latest updates for operating systems.

Parameters
PS> ./list-os-updates.ps1 [[-RSS_URL] <String>] [[-MaxCount] <Int32>] [<CommonParameters>]

-RSS_URL <String>
    Specifies the URL to the RSS feed
    
    Required?                    false
    Position?                    1
    Default value                https://distrowatch.com/news/dwd.xml
    Accept pipeline input?       false
    Accept wildcard characters?  false

-MaxCount <Int32>
    Specifies the number of news to list
    
    Required?                    false
    Position?                    2
    Default value                30
    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.

list-passwords.ps1

list-passwords.ps1

Prints a list of random passwords.

This PowerShell script lists random passwords.

:: tabs

@tab:active Parameters

PS> ./list-passwords.ps1 [[-PasswordLength] <Int32>] [[-Columns] <Int32>] [[-Rows] <Int32>] [<CommonParameters>]

-PasswordLength <Int32>
    Specifies the length of the password
    
    Required?                    false
    Position?                    1
    Default value                15
    Accept pipeline input?       false
    Accept wildcard characters?  false

-Columns <Int32>
    Specifies the number of columns
    
    Required?                    false
    Position?                    2
    Default value                6
    Accept pipeline input?       false
    Accept wildcard characters?  false

-Rows <Int32>
    Specifies the number of rows
    
    Required?                    false
    Position?                    3
    Default value                30
    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.

@tab Example

PS> ./list-passwords.ps1
# 
# 
# 
# "4yE=[mu"Az|IE@   PZ}E9Q"&?.!%49`   zU3[E7`xA)(6W_3   :wd'a(O@fr}.Z8=
# ...
# 

@tab Script Content

<#
.SYNOPSIS
	Lists random passwords
.DESCRIPTION
	This PowerShell script lists random passwords.
.PARAMETER PasswordLength
	Specifies the length of the password
.PARAMETER Columns
	Specifies the number of columns
.PARAMETER Rows
	Specifies the number of rows
.EXAMPLE
	PS> ./list-passwords.ps1

	"4yE=[mu"Az|IE@   PZ}E9Q"&?.!%49`   zU3[E7`xA)(6W_3   :wd'a(O@fr}.Z8=
	...
.LINK
	https://github.com/fleschutz/PowerShell
.NOTES
	Author: Markus Fleschutz | License: CC0
#>

param([int]$PasswordLength = 15, [int]$Columns = 6, [int]$Rows = 30)

$MinCharCode = 33
$MaxCharCode = 126

try {
	write-output ""
	$Generator = New-Object System.Random
	for ($j = 0; $j -lt $Rows; $j++) {
		$Line = ""
		for ($k = 0; $k -lt $Columns; $k++) {
			for ($i = 0; $i -lt $PasswordLength; $i++) {
				$Line += [char]$Generator.next($MinCharCode,$MaxCharCode)
			}
			$Line += "   "
		}
		write-output "$Line"
	}
	write-output ""
	exit 0 # success
} catch {
	"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
	exit 1
}

:::


list-pins.ps1

list-pins.ps1

Prints a list of random PIN's.

This PowerShell script lists random PIN's.

Parameters
PS> ./list-pins.ps1 [[-PinLength] <Int32>] [[-Columns] <Int32>] [[-Rows] <Int32>] [<CommonParameters>]

-PinLength <Int32>
    Specifies the PIN length
    
    Required?                    false
    Position?                    1
    Default value                5
    Accept pipeline input?       false
    Accept wildcard characters?  false

-Columns <Int32>
    Specifies the number of columns
    
    Required?                    false
    Position?                    2
    Default value                12
    Accept pipeline input?       false
    Accept wildcard characters?  false

-Rows <Int32>
    Specifies the number of rows
    
    Required?                    false
    Position?                    3
    Default value                30
    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.

list-sql-tables.ps1

list-sql-tables.ps1

Lists the SQL server tables.

This PowerShell script lists all tables in a SQL server database and exports the list as CSV.

Install-Module InvokeQuery

Run the above command if you do not have this module.

Parameters
PS> ./list-sql-tables.ps1 [-server] <Object> [-database] <Object> [-username] <Object> [-password] <Object> [<CommonParameters>]

-server <Object>
    
    Required?                    true
    Position?                    1
    Default value                
    Accept pipeline input?       false
    Accept wildcard characters?  false

-database <Object>
    
    Required?                    true
    Position?                    2
    Default value                
    Accept pipeline input?       false
    Accept wildcard characters?  false

-username <Object>
    
    Required?                    true
    Position?                    3
    Default value                
    Accept pipeline input?       false
    Accept wildcard characters?  false

-password <Object>
    
    Required?                    true
    Position?                    4
    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.

list-weather.ps1

list-weather.ps1

Lists the hourly weather.

This PowerShell script lists the hourly weather report in a nice table.

Parameters
PS> ./list-weather.ps1 [[-Location] <String>] [<CommonParameters>]

-Location <String>
    Specifies the location to use (determined automatically per default)
    
    Required?                    false
    Position?                    1
    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.

locate-city.ps1

locate-city.ps1

Prints the geographic location of the given city.

This PowerShell script prints the geographic location of the given city.

Parameters
PS> ./locate-city.ps1 [[-City] <String>] [<CommonParameters>]

-City <String>
    Specifies the city to look for
    
    Required?                    false
    Position?                    1
    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.

locate-ipaddress.ps1

locate-ipaddress.ps1

Prints the geographic location of the given IP address.
Parameters
PS> ./locate-ipaddress.ps1 [<CommonParameters>]

[<CommonParameters>]
    This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, 
    WarningVariable, OutBuffer, PipelineVariable, and OutVariable.

moon.ps1

moon.ps1

Prints the current moon phase.

This PowerShell script prints the current moon phase.

Parameters
PS> ./moon.ps1 [<CommonParameters>]

[<CommonParameters>]
    This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, 
    WarningVariable, OutBuffer, PipelineVariable, and OutVariable.

scan-ports.ps1

scan-ports.ps1

Scans the network for open/closed ports.

This PowerShell script scans the network for open or closed ports.

Parameters
PS> ./scan-ports.ps1 [<CommonParameters>]

[<CommonParameters>]
    This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, 
    WarningVariable, OutBuffer, PipelineVariable, and OutVariable.

send-tcp.ps1

send-tcp.ps1

Sends a TCP message to the given IP address and port.

This PowerShell script sends a TCP message to the given IP address and port.

Parameters
PS> ./send-tcp.ps1 [[-TargetIP] <String>] [[-TargetPort] <Int32>] [[-Message] <String>] [<CommonParameters>]

-TargetIP <String>
    Specifies the target IP address
    
    Required?                    false
    Position?                    1
    Default value                
    Accept pipeline input?       false
    Accept wildcard characters?  false

-TargetPort <Int32>
    Specifies the target port number
    
    Required?                    false
    Position?                    2
    Default value                0
    Accept pipeline input?       false
    Accept wildcard characters?  false

-Message <String>
    Specifies the message to send
    
    Required?                    false
    Position?                    3
    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.

send-udp.ps1

send-udp.ps1

Sends a UDP datagram message to the given IP address and port.

This PowerShell script sends a UDP datagram message to an IP address and port.

Parameters
PS> ./send-udp.ps1 [[-TargetIP] <String>] [[-TargetPort] <Int32>] [[-Message] <String>] [<CommonParameters>]

-TargetIP <String>
    Specifies the target IP address
    
    Required?                    false
    Position?                    1
    Default value                
    Accept pipeline input?       false
    Accept wildcard characters?  false

-TargetPort <Int32>
    Specifies the target port number
    
    Required?                    false
    Position?                    2
    Default value                0
    Accept pipeline input?       false
    Accept wildcard characters?  false

-Message <String>
    Specifies the message text to send
    
    Required?                    false
    Position?                    3
    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.

set-timer.ps1

set-timer.ps1

Sets a timer for a countdown.

This PowerShell script sets a timer for a countdown.

Parameters
PS> ./set-timer.ps1 [[-Seconds] <Int32>] [<CommonParameters>]

-Seconds <Int32>
    Specifies the number of seconds
    
    Required?                    false
    Position?                    1
    Default value                0
    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.

simulate-presence.ps1

simulate-presence.ps1

Simulates the human presence against burglars.

This PowerShell script simulates the human presence against burglars. It switches a Shelly1 device on and off.

Parameters
PS> ./simulate-presence.ps1 [[-IPaddress] <String>] [<CommonParameters>]

-IPaddress <String>
    Specifies the IP address of the Shelly1 device
    
    Required?                    false
    Position?                    1
    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.

start-ipfs-server.ps1

start-ipfs-server.ps1

Starts a local IPFS server.

This PowerShell script starts a local IPFS server as a daemon process.

Parameters
PS> ./start-ipfs-server.ps1 [<CommonParameters>]

[<CommonParameters>]
    This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, 
    WarningVariable, OutBuffer, PipelineVariable, and OutVariable.

translate-file.ps1

translate-file.ps1

Translates the given text file into other languages.

This PowerShell script translates the given text file into another language and writes the output on the console.

Parameters
PS> ./translate-file.ps1 [[-File] <String>] [[-SourceLang] <String>] [[-TargetLang] <String>] [<CommonParameters>]

-File <String>
    Specifies the path to the file to be translated
    
    Required?                    false
    Position?                    1
    Default value                
    Accept pipeline input?       false
    Accept wildcard characters?  false

-SourceLang <String>
    Specifies the source language
    
    Required?                    false
    Position?                    2
    Default value                
    Accept pipeline input?       false
    Accept wildcard characters?  false

-TargetLang <String>
    Specifies the target language
    
    Required?                    false
    Position?                    3
    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.

translate-files.ps1

translate-files.ps1

Translates the given text files into any supported language.

This PowerShell script translates text files into multiple languages.

Parameters
PS> ./translate-files.ps1 [[-filePattern] <String>] [<CommonParameters>]

-filePattern <String>
    Specifies the file pattern of the text file(s) to be translated
    
    Required?                    false
    Position?                    1
    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.

translate-text.ps1

translate-text.ps1

Translates the given text in English into other languages.

This PowerShell script translates text into other languages.

Parameters
PS> ./translate-text.ps1 [[-Text] <String>] [[-SourceLangCode] <String>] [[-TargetLangCode] <String>] [<CommonParameters>]

-Text <String>
    Specifies the text to translate
    
    Required?                    false
    Position?                    1
    Default value                
    Accept pipeline input?       false
    Accept wildcard characters?  false

-SourceLangCode <String>
    
    Required?                    false
    Position?                    2
    Default value                en
    Accept pipeline input?       false
    Accept wildcard characters?  false

-TargetLangCode <String>
    
    Required?                    false
    Position?                    3
    Default value                all
    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.

weather.ps1

weather.ps1

Prints the current weather forecast.

This PowerShell script lists the current weather forecast.

Parameters
PS> ./weather.ps1 [[-GeoLocation] <String>] [<CommonParameters>]

-GeoLocation <String>
    Specifies the geographic location to use
    
    Required?                    false
    Position?                    1
    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.

weather-report.ps1

weather-report.ps1

Prints the local weather report.

This PowerShell script lists the local weather report.

Parameters
PS> ./weather-report.ps1 [[-GeoLocation] <String>] [<CommonParameters>]

-GeoLocation <String>
    Specifies the geographic location to use (determine automatically by default)
    
    Required?                    false
    Position?                    1
    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.

이찬희 (MarkiiimarK)
Never Stop Learning.