Skip to content

hugoremington/PowerShell-GUI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

PowerShell GUI (Threaded)

Version Author PowerShell

A high-performance, professional-grade Windows Forms (WinForms) template for PowerShell developers. This script provides a fully functional GUI scaffold that solves the most common problem in PowerShell GUI development: the UI freezing during execution.

✨ Key Features

  • 🚀 Multi-Threaded Engine: Uses RunspacePool to execute heavy logic in the background, ensuring the user interface remains smooth and interactive.
  • 🧠 Intelligent CPU Scaling: Automatically detects the host machine's processor count ($env:NUMBER_OF_PROCESSORS) to optimize the thread pool size.
  • 💬 Real-Time Color Logging: A built-in RichTextBox output window supports color-coded logging (Green for success, Red for errors) to keep the user informed.
  • 📂 Smart File Integration: Includes a robust file browser for .txt and .csv files, complete with automatic line counting and validation.
  • 🛠 Thread-Safe Communication: Utilises a [hashtable]::Synchronized object to allow background threads to safely update the UI (progress bars, text boxes, etc.) without causing race conditions.
  • 🎄 Seasonal Easter Egg: The GUI features a dynamic theme! Between December 25th and January 2nd, the UI automatically switches to a festive "Merry Christmas" mode with a custom color scheme.

🏗 Technical Architecture

This template is designed for stability and performance using the following components:

Component Purpose
RunspacePool Manages a collection of background threads to prevent UI blocking.
Synchronized Hashtable Acts as a bridge between the Background Thread and the UI Thread.
SessionStateVariableEntry Injects the shared hashtable into the background runspace for seamless data passing.
WinForms Provides the graphical interface (Buttons, Progress Bars, Menus).

🚀 Quick Start

1. Integrating your logic

To use this as a template, simply replace the contents of the $scriptRun block with your own code:

$scriptRun = {
    # Your heavy-duty logic goes here
    # Use $hash.outputBox to log messages
    # Use $hash.progressBar1 to update progress
    $hash.OutputBox.AppendText("`r`nStarting task...")
}

About

GUI template for PowerShell with multi-threading

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors