Skip to content

Instantly share code, notes, and snippets.

View scriptingstudio's full-sized avatar
👍
Awake and ready

Matthew Gray scriptingstudio

👍
Awake and ready
  • Interstellar Systems
  • Hiranyaloka
View GitHub Profile
@dfinke
dfinke / ChatMediator.ps1
Created June 21, 2024 14:06
Demonstrates the implementation of the Mediator Design Pattern in PowerShell
<#
Define an object that encapsulates how a set of objects interact.
Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and it lets you vary their interaction independently.
#>
class ChatMediator {
$users
ChatMediator() {
$this.users = New-Object System.Collections.ArrayList
@dfinke
dfinke / FinanceReport.ps1
Last active July 3, 2024 17:24
PowerShell script using the Template Method pattern to generate financial reports in plain text and HTML formats. Extensible and flexible.
class ReportTemplate {
hidden $data
GenerateReport() {
$this.RetrieveFinancialData()
$this.FormatReport()
$this.SendToStakeholders()
}
RetrieveFinancialData() {
class Command {
execute() {
"[$(get-date)] Logging execute of command [$this]" | Out-Host # Logs the execution of the command
}
}
class Loony : Command {
execute() {
([Command]$this).execute() # Calls the execute method of the base class (Command)
"You're a loony." | Out-Host # Outputs "You're a loony."
@dfinke
dfinke / Logger-DecoratorPattern.ps1
Last active July 3, 2024 17:27
PowerShell Decorator Pattern: Enhance Logger with Timestamp and Uppercase
class Logger {
log($message) { # Define a method called "log" that takes a message as input
$message | Out-Host # Output the message to the console
}
}
class TimeStampingLogger : Logger { # Define a class called "TimeStampingLogger" that inherits from "Logger"
$logger # Declare a variable called "logger"
TimeStampingLogger($logger) { # Define a constructor that takes a "logger" as input
@dfinke
dfinke / ClockObserverPattern.ps1
Last active July 14, 2024 05:01
PowerShell implementation of the Observer Pattern with a Clock Timer example, featuring Digital and Analog clocks.
class Subject {
hidden [System.Collections.ArrayList]$observers
Subject() {
$this.observers = New-Object System.Collections.ArrayList
}
Attach([Observer]$o) { $this.observers.Add($o) }
@dfinke
dfinke / Try-CompositePattern.ps1
Last active July 3, 2024 17:29
Composite Pattern: Simplifies client code by treating individual objects and compositions uniformly, making it easier to work with complex structures
. .\Employee.ps1
$CEO = [Employee]::new("John","CEO", 30000)
$HeadSales = [Employee]::new("Robert","Head Sales", 20000)
$HeadMarketing = [Employee]::new("Michel","Head Marketing", 20000)
$clerk1 = [Employee]::new("Laura","Marketing", 10000)
$clerk2 = [Employee]::new("Bob","Marketing", 10000)
$salesExecutive1 = [Employee]::new("Richard","Sales", 10000)
$salesExecutive2 = [Employee]::new("Rob","Sales", 10000)
@jdhitsolutions
jdhitsolutions / PSRefresh.ps1
Last active July 5, 2024 22:49
Refresh a new Windows PowerShell Installation.
#requires -version 5.1
#requires -RunAsAdministrator
#PSRefresh.ps1
<#
Update key PowerShell components on a new Windows 10/11 installation.
This script is not intended for server operating systems. The script
should be run in an interactive console session and not in a remoting session.
@dfinke
dfinke / grades-vlookup.ps1
Last active July 15, 2024 06:10
With PowerShell Excel - use VLOOKUP to explain data
$data = ConvertFrom-Csv @'
Name,Score,Grade
Ahmed,76
Bassam,91
Amira,42
Nadia,83
Joseph,36
Mary,45
Ashraf,81
Amal,56
@laymanstake
laymanstake / Start-ADAssessment.ps1
Last active July 9, 2024 12:34
The script to perform AD assessment including ADFS, ADSync checks
#Requires -Version 3.0
#Requires -Modules ActiveDirectory, GroupPolicy, DnsServer
<#
Author : Nitish Kumar
Performs Active Directory Forest Assessment
version 1.0 | 06/06/2023 Initial version
version 1.1 | 15/06/2023 Covered most areas though error proofing and dependency over wsman still remains
version 1.2 | 16/06/2023 Number of small fixes included wrong calulations on empty groups
version 1.3 | 21/06/2023 PowerShell jobs for AD health checks and Domain Summary details, Also chosing least latency DC
@tatyanavolkova
tatyanavolkova / README.md
Last active December 29, 2022 17:51 — forked from djiwondee/README.md
Dashboard with current conditions and forecast