2020-06-19 18:00:03 +02:00
Collection of Useful PowerShell Scripts (CUPS)
==============================================
2020-05-01 11:44:56 +02:00
2020-12-08 21:34:55 +01:00
This repository contains 40+ useful cross-platform PowerShell scripts - to be used on the command-line (CLI), by context menu, by voice control, or by automation software (e.g. Jenkins).
2020-05-01 11:44:56 +02:00
2020-10-03 23:43:59 +02:00
List of Scripts
---------------
2020-12-08 16:13:55 +01:00
The following PowerShell scripts can be found in the [Scripts/ ](Scripts/ ) subfolder:
2020-10-03 23:43:59 +02:00
2020-12-01 12:24:56 +01:00
* [clone-repos.ps1 ](Scripts/clone-repos.ps1 ) - clones well-known Git repositories
2020-12-02 08:27:07 +01:00
* [configure-git.ps1 ](Scripts/configure-git.ps1 ) - sets up the Git configuration
2020-09-29 20:35:44 +02:00
* [download.ps1 ](Scripts/download.ps1 ) - downloads the file/directory from the given URL
2020-10-06 16:23:20 +02:00
* [empty-dir.ps1 ](Scripts/empty-dir.ps1 ) - empties the given directory
2020-12-08 16:01:57 +01:00
* [inspect-exe.ps1 ](Scripts/inspect-exe.ps1 ) - prints basic information of the given executable file
2020-11-01 12:20:55 +01:00
* [latlong.ps1 ](Scripts/latlong.ps1 ) - prints the lat/long coordinates of the given city
2020-10-10 18:18:53 +02:00
* [list-empty-dirs.ps1 ](Scripts/list-empty-dirs.ps1 ) - lists empty subfolders in a directory tree
* [list-unused-files.ps1 ](Scripts/list-unused-files.ps1 ) - lists unused files in a directory tree
2020-10-10 18:35:22 +02:00
* [list-cmdlets.ps1 ](Scripts/list-cmdlets.ps1 ) - lists the PowerShell cmdlets
* [list-modules.ps1 ](Scripts/list-modules.ps1 ) - lists the PowerShell modules
* [list-processes.ps1 ](Scripts/list-processes.ps1 ) - lists the local computer processes
2020-09-25 15:03:48 +02:00
* [MD5.ps1 ](Scripts/MD5.ps1 ) - prints the MD5 checksum of the given file
2020-10-02 09:29:24 +02:00
* [make-install.ps1 ](Scripts/make-install.ps1 ) - installs built executables and libs to the installation directory
2020-09-25 15:03:48 +02:00
* [moon.ps1 ](Scripts/moon.ps1 ) - prints the current moon phase
* [password.ps1 ](Scripts/password.ps1 ) - generates and prints a single new password
* [passwords.ps1 ](Scripts/passwords.ps1 ) - generates and prints a list of new passwords
* [poweroff.ps1 ](Scripts/poweroff.ps1 ) - halts the local computer, administrator rights might be needed
* [news.ps1 ](Scripts/news.ps1 ) - prints the latest news
* [reboot.ps1 ](Scripts/reboot.ps1 ) - reboots the local computer, administrator rights might be needed
2020-11-28 10:00:04 +01:00
* [scan-ports.ps1 ](Scripts/scan-ports.ps1 ) - scans the network for open/closed ports
2020-11-28 09:18:36 +01:00
* [send-email.ps1 ](Scripts/send-email.ps1 ) - sends an email message
* [send-udp.ps1 ](Scripts/send-udp.ps1 ) - sends a UDP datagram message to the given IP address and port
2020-09-25 15:03:48 +02:00
* [SHA1.ps1 ](Scripts/SHA1.ps1 ) - prints the SHA1 checksum of the given file
* [SHA256.ps1 ](Scripts/SHA256.ps1 ) - prints the SHA256 checksum of the given file
2020-11-30 16:28:56 +01:00
* [simulate-presence.ps1 ](Scripts/simulate-presence.ps1 ) - simulates the human presence against burglars
2020-12-08 16:11:01 +01:00
* [speak-file.ps1 ](Scripts/speak-file.ps1 ) - speaks the content of the given text file by text-to-speech (TTS)
* [speak-text.ps1 ](Scripts/speak-text.ps1 ) - speaks the given text by text-to-speech (TTS)
2020-12-01 10:54:41 +01:00
* [switch-shelly1.ps1 ](Scripts/switch-shelly1.ps1 ) - switches a Shelly1 device in the local network
2020-11-22 11:06:31 +01:00
* [take-screenshot.ps1 ](Scripts/take-screenshot.ps1 ) - takes a single screenshot
* [take-screenshots.ps1 ](Scripts/take-screenshots.ps1 ) - takes multiple screenshots
2020-09-25 15:03:48 +02:00
* [test.ps1 ](Scripts/test.ps1 ) - simple test script
2020-10-10 18:29:29 +02:00
* [train-dns-cache.ps1 ](Scripts/train-dns-cache.ps1 ) - trains the DNS cache with frequently used domain names
2020-12-08 13:36:22 +01:00
* [translate-text.ps1 ](Scripts/translate-text.ps1 ) - translates the given text into other languages
2020-09-25 15:03:48 +02:00
* [txt2wav.ps1 ](Scripts/txt2wav.ps1 ) - converts text into a audio .WAV file
2020-10-10 18:26:29 +02:00
* [validate-xml.ps1 ](Scripts/validate-xml.ps1 ) - validates the given XML file
2020-09-25 15:03:48 +02:00
* [weather.ps1 ](Scripts/weather.ps1 ) - prints the current weather forecast
2020-11-11 21:00:51 +01:00
* [weather-alert.ps1 ](Scripts/weather-alert.ps1 ) - checks the current weather for critical values
2020-11-11 11:12:18 +01:00
* [weather-report.ps1 ](Scripts/weather-report.ps1 ) - prints the local weather report
2020-11-11 11:03:50 +01:00
* [weather-worldwide.ps1 ](Scripts/weather-worldwide.ps1 ) - prints the current weather of cities world-wide
2020-09-25 15:03:48 +02:00
* [wakeup.ps1 ](Scripts/wakeup.ps1 ) - sends a magic packet to the given computer, waking him up
2020-11-22 10:22:35 +01:00
* [zip-dir.ps1 ](Scripts/zip-dir.ps1 ) - creates a zip archive of the given folder
2020-05-22 09:54:16 +02:00
2020-12-08 21:25:56 +01:00
2020-08-11 13:48:27 +02:00
What is PowerShell?
-------------------
2020-05-04 14:39:06 +02:00
PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language.
2020-08-11 14:15:02 +02:00
* it's **cross-platform** : available for Linux, Mac OS and Windows
2020-08-11 13:51:30 +02:00
* it's **powerful** : fully control your computer
* it's **open-source** : see the Github repository at https://github.com/PowerShell/PowerShell
* it's **easy to learn** : see the tutorial at https://www.guru99.com/powershell-tutorial.html
* it's **fully documented** : see the official docs at https://docs.microsoft.com/en-us/powershell/
2020-05-01 11:44:56 +02:00
2020-08-11 13:48:27 +02:00
How to get PowerShell?
----------------------
2020-12-08 21:40:13 +01:00
* **Windows 7 and newer** do provide PowerShell by default. It's recommended to install **Windows Terminal** (see the Microsoft Store at https://www.aka.ms/terminal) for a comfortable command-line usage.
* **On CentOS, Debian, Docker, Fedora, macOS, openSUSE, Red Hat, Ubuntu** visit https://github.com/PowerShell/PowerShell for installation.
2020-08-11 14:11:48 +02:00
2020-12-08 21:40:13 +01:00
Afterward, install CUPS by clicking on the green "Code" button or execute:
2020-08-11 14:27:11 +02:00
```
$ git clone https://github.com/fleschutz/PowerShell
```
2020-08-11 13:48:27 +02:00
2020-12-08 21:25:56 +01:00
Configure PowerShell as Default Shell
-------------------------------------
* **Linux:** make sure PowerShell is installed, then execute: `chsh -s /snap/bin/powershell <username>`
* **Windows:** no need to, PowerShell is the default shell
2020-06-15 16:01:12 +02:00
2020-06-15 15:56:18 +02:00
2020-12-08 21:25:56 +01:00
Adding Subfolder Scripts/ to the Search Path for Command-line Usage
-------------------------------------------------------------------
* **Bash or sh:** edit .profile in your home directory and add the line: PATH="$PATH:/path/to/PowerShell/Scripts"
* **Windows:** open the environment variables dialogue and add the full path to Scripts/ to the system environment variable "Path"
2020-08-11 14:11:48 +02:00
2020-06-15 16:01:12 +02:00
2020-12-08 21:25:56 +01:00
Using PowerShell in Windows Context Menus
------------------------------------------
* to enable "right-click > New > Windows PowerShell Script" just execute Context_Menus/add_ps1_to_New_context_menu.reg
* to disable it just execute Context_Menus/remove_ps1_from_New_context_menu.reg
2020-05-25 20:37:47 +02:00
2020-12-08 21:25:56 +01:00
Script Conventions
------------------
2020-11-30 16:37:02 +01:00
Each PowerShell script should follow the 7 golden rules:
2020-12-08 21:25:56 +01:00
* **Rule 1:** the filename should be named `<verb>-<object>.ps1`
2020-11-30 16:37:02 +01:00
* **Rule 2:** to support PowerShell on Linux the first line reads: #!/snap/bin/powershell
* **Rule 3:** to support PowerShell on Linux the script has execute file permissions (chmod a+rx < file > )
* **Rule 4:** add a metadata header containing the syntax, description, author, source, and license
* **Rule 5:** prefer command-line options, but may ask the user in case no option is given
* **Rule 6:** the encoding of the script is in UTF-8 with BOM to support Unicode characters
2020-12-08 21:31:26 +01:00
* **Rule 7:** exit 0 for success, else print an error message and exit with the error code (mostly 1)
2020-05-02 13:01:03 +02:00
2020-06-15 15:09:54 +02:00
Feedback
--------
2020-06-15 16:01:12 +02:00
Send your email feedback to: markus [at] fleschutz [dot] de
2020-06-15 15:09:54 +02:00
2020-05-02 13:01:03 +02:00
License & Copyright
-------------------
This open source release is licensed under the CC0 license. All trademarks are the property of their respective owners.