500+ PowerShell scripts (.ps1) for every system!
Go to file
2021-02-09 19:30:45 +01:00
Data Added remove-empty-dirs.ps1 2021-02-09 14:46:54 +01:00
Misc Renamed to Misc/ 2020-12-25 11:03:01 +00:00
Scripts Changed to #!/bin/powershell 2021-02-09 19:30:45 +01:00
LICENSE Initial commit 2020-04-30 17:49:27 +02:00
README.md Changed to #!/bin/powershell 2021-02-09 19:30:45 +01:00

Collection of PowerShell Scripts

This repository contains 120+ useful and cross-platform PowerShell scripts - to be used by command-line interface (CLI), for remote control (RC), by context menu, by voice control, by automation software like Jenkins, as daily tasks, or simply to learn PowerShell.

The following PowerShell scripts can be found in the Scripts/ subfolder:

What is PowerShell?

PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language.

How to get PowerShell?

  • 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. Per default, Windows does not allow script execution (execution policy "restricted"). To enable this, enter as administrator:
    $ Set-ExecutionPolicy RemoteSigned
    
  • On CentOS, Debian, Docker, Fedora, macOS, openSUSE, Red Hat, Ubuntu visit https://github.com/PowerShell/PowerShell for installation.

Afterward, install this collection by clicking on the green "Code" button or execute:

$ git clone https://github.com/fleschutz/PowerShell

Configure PowerShell as Default Shell

  • Linux: make sure PowerShell is installed, then execute: chsh -s /bin/powershell <username>
  • Windows: no need to, PowerShell is the default shell

Adding the Scripts to the Search Path

Want to use the PowerShell scripts everywhere on the command-line? Then you need to add the Scripts/ subfolder to the search path:

  • 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"

Using PowerShell in Context Menus

  • to enable "right-click > New > Windows PowerShell Script" execute Add_ps1_to_New_context_menu.reg in subfolder Misc/
  • to disable this execute Remove_ps1_from_New_context_menu.reg in subfolder Misc/

Script Conventions

Each PowerShell script should follow the 8 golden rules:

  1. the filename should be named <verb>-<object>.ps1
  2. the first line reads #!/bin/powershell to support PowerShell on Linux
  3. the script has execute file permissions (chmod a+rx ) to support PowerShell on Linux
  4. provide a comment-based help with syntax, description, link, author, and license
  5. prefer command-line options, else ask the user
  6. use Set-StrictMode -Version Latest to enable additional error checking
  7. for readibility use UpperCamelCase for variables and functions, lowerCamelCase for everything else
  8. exit 0 for success, else print an error message and exit with the error code (mostly 1)

Feedback

Send your email feedback to: markus [at] fleschutz [dot] de

This open source release is licensed under the CC0 license. All trademarks are the property of their respective owners.