fleschutz/powershell Script Collection

repository·main·Indexed 25 days ago

https://github.com/fleschutz/powershell

A collection of over 600 stand-alone PowerShell scripts for Windows, macOS, and Linux. The repository covers audio/voice, computer management, desktop automation, system monitoring, and file utilities. It includes PowerShell Commander, a GUI application requiring Python 3.8+ and PowerShell 5.1+ or PowerShell Core, which allows users to organize, manage, and execute scripts via a visual Script Manager.

Tokens
177.7K
Snippets
901
Records
1.8K
Agent score
83%

What's inside fleschutz/powershell

  1. Overview of PowerShell Script Collection

    main
    The fleschutz/powershell repository is a collection of over 600 free, stand-alone PowerShell scripts designed for Linux, macOS, and Windows. These scripts are suitable for use in the command-line (CLI), remote control via SSH, automation (startup, shutdown, login, logoff, scheduled tasks), context menus, or integration with tools like AutoHotkey, Jenkins, or voice command systems. All scripts are located in the scripts/ directory and support Unicode for modern consoles like Windows Terminal.
  2. Understand the 'play-drug-wars.ps1' script structure

    main

    The play-drug-wars.ps1 script is a PowerShell-based game. It utilizes several internal functions to manage the user experience, including:

    • UI Management: Functions like ShowTitleScreen handle ASCII art rendering, centering content based on console dimensions, and managing foreground/background colors.
    • Game State: The script manages game statistics and high scores.
    • Input Handling: It includes logic to detect key presses (e.g., Enter to exit loops) and manages text animations/taglines.
    • Data Persistence: High scores are managed via a highscores.json file.

    Note: The script uses Write-Centered and GetTagLineAlternateText which are part of its internal logic to provide a polished terminal interface.

  3. Understand the 'play-drug-wars.ps1' script logic

    main

    The play-drug-wars.ps1 script is a text-based game simulation. This segment of the script handles several random encounter events:

    1. Shady Dealer Encounter: A user can choose to accept a cocktail of random drugs. This results in either a 'tripout' (losing a game day via AdvanceGameDay -SkipPriceUpdate) or finding extra cash ($script:Player.Cash += $cashToAdd).
    2. Junkie Challenge (Street Smarts): A trivia-based mini-game. The script presents random questions about substances. After the trivia sequence, a win/loss is determined randomly. Winning adds cash to $script:Player.Cash, while losing subtracts it.
    3. Hidden Stash: An encounter where the player can choose to 'yoink' a hidden stash of drugs.

    Note: The script uses Write-Centered for UI output and Start-Sleep to manage game pacing.

  4. List WSL Linux distributions with list-wsl-distros.ps1

    main

    Use the list-wsl-distros.ps1 script to list all installed/available Linux distributions for Windows Subsystem for Linux (WSL). The script outputs the names, states, and versions of local distributions, lists available online distributions, and shows the current WSL status.

    Note: This script requires Windows Subsystem for Linux (WSL) and will fail if run on Linux or macOS.

    PS> ./list-wsl-distros.ps1
    
    NAME            STATE           VERSION
    * Ubuntu-24.04    Stopped         2
    ...
  5. Best practices for writing PowerShell scripts

    main

    To ensure scripts are user-friendly, platform-independent, and secure, follow these guidelines:

    • Naming: Use the <verb>-<object>[-<detail]>.ps1 convention (e.g., new-symlink.ps1). Use approved verbs.
    • Encoding: Use UTF-8 BOM to support Unicode characters.
    • Documentation: Include a synopsis block at the start with .SYNOPSIS, .DESCRIPTION, .PARAMETER, .EXAMPLE, .LINK, and .NOTES.
    • Requirements: Explicitly state requirements using #Requires -RunAsAdministrator or #Requires -Version 5.
    • Security: Never hardcode secrets (passwords, keys, etc.); use parameters instead.
    • Error Handling: Use Set-StrictMode -Version Latest for better error checking. On success, exit with exit 0. On error, print the error with the prefix ERROR: and exit with a non-zero code (e.g., exit 1).
    • Coding Style: Use lowerCamelCase for variables and functions.
    • Linux Permissions: Set execution permissions using chmod a+rx <filename>.
  6. Export PowerShell scripts to Serenade

    main

    Use the export-to-serenade.ps1 script to export your PowerShell scripts into a Serenade-compatible JavaScript file. This allows you to execute your PowerShell scripts using voice commands via the Serenade framework.

    By default, the script scans for all .ps1 files in the current script directory ($PSScriptRoot/*.ps1) and writes the output to $HOME\.serenade\scripts\PowerShell.js using the terminal application.

    ./export-to-serenade.ps1 Computer
  7. Configure Git user settings with configure-git.ps1

    main

    The configure-git.ps1 script automates the setup of your global Git configuration. It performs five main tasks:

    1. Verifies the Git executable is installed.
    2. Collects user details (name, email, and preferred editor).
    3. Configures basic settings (e.g., core.autocrlf, core.symlinks, core.longpaths, init.defaultBranch, merge.renamelimit, pull.rebase, and fetch.parallel).
    4. Sets user identity (user.name, user.email) and the global editor (core.editor).
    5. Configures a set of common Git aliases (e.g., br for branch, st for status, co for checkout).

    If parameters are not provided via the command line, the script will prompt you for them interactively.

    ./configure-git.ps1 "Joe Doe" joe@doe.com vim
  8. Install fonts using install-fonts.ps1

    main

    Use the install-fonts.ps1 script to automate the installation of TrueType (.ttf) fonts by copying them to the Windows Fonts directory and adding the necessary registry entries.

    Usage Modes:

    1. Direct Path: Provide the path to the folder containing your .ttf files as a parameter.
    2. Interactive: Run the script without parameters, and it will prompt you to enter the source folder path via Read-Host.

    Requirements:

    • PowerShell version 5.1 or higher.
    • Administrative privileges (required to write to $env:SystemRoot\Fonts and HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts).
  9. Understand 'Needle Nook' event mechanics in play-drug-wars.ps1

    main
    The Needle Nook event triggers a random interaction in a dimly lit alley. One possible outcome involves a shady dealer offering a mysterious drug cocktail, which the player can choose to accept or decline via a (Y/N) prompt.
  10. Use the check-software.ps1 script to query local software status

    main

    The check-software.ps1 script queries the software status of the local computer and prints a summary to the console. It acts as a wrapper that executes several sub-scripts to provide a comprehensive overview of the OS, uptime, installed applications, PowerShell version, time zone, and swap space.

    PS> ./check-software.ps1