Simple System Health Monitor

# Simple System Health Monitor

function Show-Menu {
    Clear-Host
    Write-Host "=== Simple System Health Monitor ===" -ForegroundColor Cyan
    Write-Host "1. Check CPU Usage"
    Write-Host "2. Check Memory Usage"
    Write-Host "3. Check Disk Space"
    Write-Host "4. List Top 5 CPU-Consuming Processes"
    Write-Host "5. Check System Uptime"
    Write-Host "6. Exit"
}

function Check-CPUUsage {
    $cpu = Get-WmiObject Win32_Processor | Measure-Object -Property LoadPercentage -Average | Select-Object Average
    Write-Host "`nCurrent CPU Usage: $($cpu.Average)%" -ForegroundColor Yellow
}

function Check-MemoryUsage {
    $os = Get-Ciminstance Win32_OperatingSystem
    $totalMemory = [math]::Round($os.TotalVisibleMemorySize / 1MB, 2)
    $freeMemory = [math]::Round($os.FreePhysicalMemory / 1MB, 2)
    $usedMemory = $totalMemory - $freeMemory
    $percentUsed = [math]::Round(($usedMemory / $totalMemory) * 100, 2)

    Write-Host "`nMemory Usage:" -ForegroundColor Yellow
    Write-Host "Total Memory: $totalMemory GB"
    Write-Host "Used Memory: $usedMemory GB"
    Write-Host "Free Memory: $freeMemory GB"
    Write-Host "Percent Used: $percentUsed%"
}

function Check-DiskSpace {
    $disks = Get-WmiObject Win32_LogicalDisk | Where-Object {$_.DriveType -eq 3}
    Write-Host "`nDisk Space:" -ForegroundColor Yellow
    foreach ($disk in $disks) {
        $freeSpace = [math]::Round($disk.FreeSpace / 1GB, 2)
        $totalSpace = [math]::Round($disk.Size / 1GB, 2)
        $usedSpace = $totalSpace - $freeSpace
        $percentFree = [math]::Round(($freeSpace / $totalSpace) * 100, 2)
        
        Write-Host "Drive $($disk.DeviceID):"
        Write-Host "  Total: $totalSpace GB"
        Write-Host "  Used: $usedSpace GB"
        Write-Host "  Free: $freeSpace GB"
        Write-Host "  Percent Free: $percentFree%"
        Write-Host ""
    }
}

function Get-TopCPUProcesses {
    Write-Host "`nTop 5 CPU-Consuming Processes:" -ForegroundColor Yellow
    Get-Process | Sort-Object CPU -Descending | Select-Object -First 5 | 
        Format-Table Name, @{Name='CPU (s)'; Expression={$_.CPU.ToString('N2')}}, @{Name='Memory (MB)'; Expression={[math]::Round($_.WorkingSet / 1MB, 2)}} -AutoSize
}

function Check-Uptime {
    $uptime = (Get-Date) - (Get-CimInstance Win32_OperatingSystem).LastBootUpTime
    Write-Host "`nSystem Uptime: $($uptime.Days) days, $($uptime.Hours) hours, $($uptime.Minutes) minutes" -ForegroundColor Yellow
}

do {
    Show-Menu
    $choice = Read-Host "`nEnter your choice (1-6)"

    switch ($choice) {
        "1" { Check-CPUUsage }
        "2" { Check-MemoryUsage }
        "3" { Check-DiskSpace }
        "4" { Get-TopCPUProcesses }
        "5" { Check-Uptime }
        "6" { Write-Host "Exiting program..." -ForegroundColor Yellow; break }
        default { Write-Host "Invalid choice. Please try again." -ForegroundColor Red }
    }

    if ($choice -ne "6") {
        Read-Host "`nPress Enter to continue..."
    }
} while ($choice -ne "6")

This System Health Monitor includes:

  1. A menu with 6 options
  2. Functions for various system health checks:
    • Checking CPU usage
    • Checking memory usage
    • Checking disk space
    • Listing top CPU-consuming processes
    • Checking system uptime
  3. Use of PowerShell cmdlets like Get-WmiObject, Get-CimInstance, and Get-Process
  4. Basic calculations for memory and disk usage percentages
  5. Formatted output for better readability

This tool provides a quick overview of essential system health metrics. It’s useful for:

  • Monitoring system performance
  • Identifying potential resource bottlenecks
  • Checking available disk space
  • Identifying processes that are consuming high CPU
  • Determining how long the system has been running

This script is suitable for users who want to perform basic system health checks without needing to navigate through multiple system tools or commands. It provides a simple interface for accessing important system information quickly and easily.

Simple Network Diagnostics Tool

# Simple Network Diagnostics Tool

function Show-Menu {
    Clear-Host
    Write-Host "=== Simple Network Diagnostics Tool ===" -ForegroundColor Cyan
    Write-Host "1. Ping a host"
    Write-Host "2. Check DNS resolution"
    Write-Host "3. View IP configuration"
    Write-Host "4. Test internet connectivity"
    Write-Host "5. Exit"
}

function Ping-Host {
    $host_name = Read-Host "Enter the host name or IP address to ping"
    Write-Host "`nPinging $host_name..." -ForegroundColor Yellow
    ping $host_name
}

function Check-DNS {
    $dns_name = Read-Host "Enter the domain name to resolve"
    Write-Host "`nResolving $dns_name..." -ForegroundColor Yellow
    nslookup $dns_name
}

function View-IPConfig {
    Write-Host "`nIP Configuration:" -ForegroundColor Yellow
    ipconfig /all
}

function Test-Internet {
    Write-Host "`nTesting internet connectivity..." -ForegroundColor Yellow
    $result = Test-Connection -ComputerName "www.google.com" -Count 2 -Quiet
    if ($result) {
        Write-Host "Internet is accessible." -ForegroundColor Green
    } else {
        Write-Host "Internet is not accessible." -ForegroundColor Red
    }
}

do {
    Show-Menu
    $choice = Read-Host "`nEnter your choice (1-5)"

    switch ($choice) {
        "1" { Ping-Host }
        "2" { Check-DNS }
        "3" { View-IPConfig }
        "4" { Test-Internet }
        "5" { Write-Host "Exiting program..." -ForegroundColor Yellow; break }
        default { Write-Host "Invalid choice. Please try again." -ForegroundColor Red }
    }

    if ($choice -ne "5") {
        Read-Host "`nPress Enter to continue..."
    }
} while ($choice -ne "5")

This simplified Network Diagnostics Tool includes:

  1. A concise menu with 5 options
  2. Basic functions for essential network diagnostic tasks:
    • Pinging a host
    • Checking DNS resolution
    • Viewing IP configuration
    • Testing internet connectivity
  3. Use of simple PowerShell cmdlets and system commands
  4. Minimal error handling
  5. Easy-to-read output

This script provides a straightforward set of tools for basic network diagnostics and troubleshooting. It’s suitable for beginners or for quick checks of common network issues. The tool uses familiar commands like ping, nslookup, and ipconfig, which are widely recognized and easy to interpret.

This simplified version is more accessible for users who need to perform basic network diagnostics without the complexity of more advanced features.

Advanced Network Diagnostics Tool

Description:

This PowerShell script creates a simple network diagnostics tool. It allows users to perform basic network troubleshooting tasks such as pinging a host, checking DNS resolution, viewing network adapter information, and performing a traceroute. The script demonstrates working with network-related cmdlets, handling user input, and presenting network information in a readable format.

Full Script:

# Advanced Network Diagnostics Tool

# Function to display the menu
function Show-Menu {
    Clear-Host
    Write-Host "=== Advanced Network Diagnostics Tool ===" -ForegroundColor Cyan
    Write-Host "1.  Ping a host"
    Write-Host "2.  Resolve DNS"
    Write-Host "3.  View network adapter information"
    Write-Host "4.  Perform traceroute"
    Write-Host "5.  View open ports"
    Write-Host "6.  Check internet connectivity"
    Write-Host "7.  View IP configuration"
    Write-Host "8.  Perform a network speed test"
    Write-Host "9.  Flush DNS cache"
    Write-Host "10. View routing table"
    Write-Host "11. Exit"
}

# Function to ping a host
function Ping-Host {
    $host_name = Read-Host "Enter the host name or IP address to ping"
    Write-Host "`nPinging $host_name..." -ForegroundColor Yellow
    $result = Test-Connection -ComputerName $host_name -Count 4 -ErrorAction SilentlyContinue
    if ($result) {
        $result | Format-Table @{Name="Source"; Expression={$_.PSComputerName}}, 
                               @{Name="Destination"; Expression={$_.Address}}, 
                               @{Name="IPV4Address"; Expression={$_.IPV4Address}}, 
                               ResponseTime
    } else {
        Write-Host "Unable to reach $host_name" -ForegroundColor Red
    }
}

# Function to resolve DNS
function Resolve-DNSName {
    $dns_name = Read-Host "Enter the domain name to resolve"
    Write-Host "`nResolving $dns_name..." -ForegroundColor Yellow
    try {
        $result = Resolve-DnsName -Name $dns_name -ErrorAction Stop
        $result | Format-Table Name, IPAddress
    } catch {
        Write-Host "Unable to resolve $dns_name. Error: $($_.Exception.Message)" -ForegroundColor Red
    }
}

# Function to view network adapter information
function View-NetworkAdapters {
    Write-Host "`nNetwork Adapter Information:" -ForegroundColor Yellow
    Get-NetAdapter | Where-Object Status -eq "Up" | Format-Table Name, InterfaceDescription, Status, LinkSpeed
}

# Function to perform traceroute
function Perform-Traceroute {
    $destination = Read-Host "Enter the destination for traceroute"
    Write-Host "`nPerforming traceroute to $destination..." -ForegroundColor Yellow
    Test-NetConnection -ComputerName $destination -TraceRoute | 
        Select-Object -ExpandProperty TraceRoute | 
        ForEach-Object { Write-Host $_ }
}

# Function to view open ports
function View-OpenPorts {
    Write-Host "`nViewing open ports..." -ForegroundColor Yellow
    Get-NetTCPConnection | Where-Object State -eq "Established" | 
        Format-Table LocalAddress, LocalPort, RemoteAddress, RemotePort, State
}

# Function to check internet connectivity
function Check-InternetConnectivity {
    Write-Host "`nChecking internet connectivity..." -ForegroundColor Yellow
    $testResult = Test-NetConnection -ComputerName "www.google.com" -InformationLevel "Detailed"
    if ($testResult.TcpTestSucceeded) {
        Write-Host "Internet is accessible." -ForegroundColor Green
    } else {
        Write-Host "Internet is not accessible." -ForegroundColor Red
    }
    $testResult | Format-List
}

# Function to view IP configuration
function View-IPConfiguration {
    Write-Host "`nIP Configuration:" -ForegroundColor Yellow
    Get-NetIPConfiguration | Format-List InterfaceAlias, IPv4Address, IPv6Address, DNSServer
}

# Function to perform a network speed test
function Perform-SpeedTest {
    Write-Host "`nPerforming network speed test..." -ForegroundColor Yellow
    # Note: This requires the installation of speedtest-cli
    # You can install it using: winget install Ookla.Speedtest.CLI
    try {
        $result = speedtest --format=json --progress=no | ConvertFrom-Json
        Write-Host "Download Speed: $([math]::Round($result.download.bandwidth / 125000, 2)) Mbps"
        Write-Host "Upload Speed: $([math]::Round($result.upload.bandwidth / 125000, 2)) Mbps"
        Write-Host "Ping: $($result.ping.latency) ms"
    } catch {
        Write-Host "Unable to perform speed test. Make sure speedtest-cli is installed." -ForegroundColor Red
    }
}

# Function to flush DNS cache
function Flush-DNSCache {
    Write-Host "`nFlushing DNS cache..." -ForegroundColor Yellow
    Clear-DnsClientCache
    Write-Host "DNS cache flushed successfully." -ForegroundColor Green
}

# Function to view routing table
function View-RoutingTable {
    Write-Host "`nRouting Table:" -ForegroundColor Yellow
    Get-NetRoute | Format-Table DestinationPrefix, NextHop, RouteMetric, ifIndex
}

# Main program loop
do {
    Show-Menu
    $choice = Read-Host "`nEnter your choice (1-11)"

    switch ($choice) {
        "1"  { Ping-Host }
        "2"  { Resolve-DNSName }
        "3"  { View-NetworkAdapters }
        "4"  { Perform-Traceroute }
        "5"  { View-OpenPorts }
        "6"  { Check-InternetConnectivity }
        "7"  { View-IPConfiguration }
        "8"  { Perform-SpeedTest }
        "9"  { Flush-DNSCache }
        "10" { View-RoutingTable }
        "11" { Write-Host "Exiting program..." -ForegroundColor Yellow; break }
        default { Write-Host "Invalid choice. Please try again." -ForegroundColor Red }
    }

    if ($choice -ne "11") {
        Read-Host "`nPress Enter to continue..."
    }
} while ($choice -ne "11")

This advanced Network Diagnostics Tool includes:

  1. A comprehensive menu with 11 options
  2. Functions for various network diagnostic tasks:
    • Pinging a host
    • Resolving DNS names
    • Viewing network adapter information
    • Performing a traceroute
    • Viewing open ports
    • Checking internet connectivity
    • Viewing IP configuration
    • Performing a network speed test (requires speedtest-cli)
    • Flushing DNS cache
    • Viewing the routing table
  3. Use of various PowerShell cmdlets related to networking
  4. Error handling for network operations
  5. Formatting of output for better readability

This script provides a more comprehensive set of tools for network diagnostics and troubleshooting. It’s suitable for users who want to perform a wider range of network-related tasks and gain more detailed insights into their network configuration and performance.

Note: The speed test function requires the installation of speedtest-cli, which can be installed using the Windows Package Manager (winget) or downloaded from the Ookla website.

Task Manager and Process Monitor

Description:

This PowerShell script creates a simple task manager and process monitor. It allows users to view running processes, sort them by various criteria, and perform basic actions like stopping a process. The script demonstrates working with processes, user input handling, and basic data manipulation in PowerShell.

Full Script:

# Task Manager and Process Monitor

# Function to display the menu
function Show-Menu {
    Clear-Host
    Write-Host "=== Task Manager and Process Monitor ===" -ForegroundColor Cyan
    Write-Host "1. View all running processes"
    Write-Host "2. View top 10 processes by CPU usage"
    Write-Host "3. View top 10 processes by Memory usage"
    Write-Host "4. Search for a process"
    Write-Host "5. Stop a process"
    Write-Host "6. Exit"
}

# Function to view all running processes
function View-AllProcesses {
    Get-Process | Format-Table Id, ProcessName, CPU, WorkingSet -AutoSize
}

# Function to view top 10 processes by CPU usage
function View-TopCPUProcesses {
    Get-Process | Sort-Object CPU -Descending | Select-Object -First 10 | 
        Format-Table Id, ProcessName, CPU -AutoSize
}

# Function to view top 10 processes by Memory usage
function View-TopMemoryProcesses {
    Get-Process | Sort-Object WorkingSet -Descending | Select-Object -First 10 | 
        Format-Table Id, ProcessName, @{Name="Memory (MB)"; Expression={[math]::Round($_.WorkingSet / 1MB, 2)}} -AutoSize
}

# Function to search for a process
function Search-Process {
    $searchTerm = Read-Host "Enter process name to search"
    Get-Process | Where-Object {$_.ProcessName -like "*$searchTerm*"} | 
        Format-Table Id, ProcessName, CPU, WorkingSet -AutoSize
}

# Function to stop a process
function Stop-UserProcess {
    $processId = Read-Host "Enter the Process ID to stop"
    try {
        Stop-Process -Id $processId -Force -ErrorAction Stop
        Write-Host "Process with ID $processId has been stopped." -ForegroundColor Green
    }
    catch {
        Write-Host "Error: Unable to stop process. $($_.Exception.Message)" -ForegroundColor Red
    }
}

# Main program loop
do {
    Show-Menu
    $choice = Read-Host "`nEnter your choice (1-6)"

    switch ($choice) {
        "1" { View-AllProcesses }
        "2" { View-TopCPUProcesses }
        "3" { View-TopMemoryProcesses }
        "4" { Search-Process }
        "5" { Stop-UserProcess }
        "6" { Write-Host "Exiting program..." -ForegroundColor Yellow; break }
        default { Write-Host "Invalid choice. Please try again." -ForegroundColor Red }
    }

    if ($choice -ne "6") {
        Read-Host "`nPress Enter to continue..."
    }
} while ($choice -ne "6")

This script includes:

  1. A menu display function for user interaction
  2. Functions to view all processes, top CPU-consuming processes, and top memory-consuming processes
  3. A function to search for processes by name
  4. A function to stop a process by its ID
  5. Use of PowerShell cmdlets like Get-Process, Stop-Process, and Format-Table
  6. Sorting and filtering of process data
  7. Basic error handling when stopping a process
  8. Formatting of output for better readability

The script provides a simple interface for users to monitor and manage system processes, making it suitable for beginners to understand PowerShell scripting concepts, process management, and data manipulation. It also introduces concepts like error handling and custom formatting of output data.

System Information Gatherer

Description:

This PowerShell script is designed for beginners to learn how to gather and display basic system information. It demonstrates how to use various PowerShell cmdlets to retrieve information about the computer’s hardware, operating system, and current user. The script also introduces basic formatting techniques to present the information in a readable manner.

Full Script:

# System Information Gatherer

# Function to get and display system information
function Get-SystemInfo {
    Clear-Host
    Write-Host "=== System Information Gatherer ===" -ForegroundColor Cyan

    # Get computer system information
    $computerSystem = Get-CimInstance CIM_ComputerSystem
    $operatingSystem = Get-CimInstance CIM_OperatingSystem

    # Display basic system information
    Write-Host "`nComputer Name: " -NoNewline -ForegroundColor Yellow
    Write-Host $computerSystem.Name

    Write-Host "Manufacturer: " -NoNewline -ForegroundColor Yellow
    Write-Host $computerSystem.Manufacturer

    Write-Host "Model: " -NoNewline -ForegroundColor Yellow
    Write-Host $computerSystem.Model

    Write-Host "Operating System: " -NoNewline -ForegroundColor Yellow
    Write-Host $operatingSystem.Caption

    Write-Host "OS Version: " -NoNewline -ForegroundColor Yellow
    Write-Host $operatingSystem.Version

    # Get and display CPU information
    $processor = Get-CimInstance CIM_Processor
    Write-Host "`nCPU Information:" -ForegroundColor Green
    Write-Host "Name: $($processor.Name)"
    Write-Host "Cores: $($processor.NumberOfCores)"
    Write-Host "Logical Processors: $($processor.NumberOfLogicalProcessors)"

    # Get and display memory information
    $totalMemory = [math]::Round($computerSystem.TotalPhysicalMemory / 1GB, 2)
    Write-Host "`nMemory Information:" -ForegroundColor Green
    Write-Host "Total Physical Memory: $totalMemory GB"

    # Get and display disk information
    Write-Host "`nDisk Information:" -ForegroundColor Green
    Get-CimInstance CIM_LogicalDisk | Where-Object {$_.DriveType -eq 3} | ForEach-Object {
        $freeSpace = [math]::Round($_.FreeSpace / 1GB, 2)
        $totalSize = [math]::Round($_.Size / 1GB, 2)
        Write-Host "Drive $($_.DeviceID): $freeSpace GB free of $totalSize GB"
    }

    # Get and display current user information
    $currentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent()
    Write-Host "`nCurrent User Information:" -ForegroundColor Green
    Write-Host "Username: $($currentUser.Name)"
}

# Main program
Get-SystemInfo

# Pause to keep the console window open
Read-Host "`nPress Enter to exit..."

This script includes:

  1. A function Get-SystemInfo that gathers and displays various system information
  2. Use of PowerShell cmdlets like Get-CimInstance to retrieve system data
  3. Formatting techniques to make the output more readable (colors, alignment)
  4. Basic math operations to convert bytes to gigabytes
  5. Use of pipeline and Where-Object for filtering disk information
  6. Retrieval of current user information

The script provides a comprehensive overview of the system’s hardware and software configuration, making it useful for beginners to understand how to access and present system information using PowerShell. It also introduces concepts like working with CIM instances, formatting output, and basic data manipulation.

Simple File Management Tool

Description:

This PowerShell script is designed for beginners to learn basic file management operations. It provides a menu-driven interface that allows users to perform common tasks such as creating directories, listing files, copying files, and deleting files. The script demonstrates the use of functions, user input handling, and basic PowerShell cmdlets for file system operations.

Full Script:

# Simple File Management Tool

# Function to display the menu
function Show-Menu {
    Clear-Host
    Write-Host "=== File Management Tool ==="
    Write-Host "1. Create a new directory"
    Write-Host "2. List files in a directory"
    Write-Host "3. Copy a file"
    Write-Host "4. Delete a file"
    Write-Host "5. Exit"
}

# Function to create a new directory
function Create-NewDirectory {
    $dirName = Read-Host "Enter the name of the new directory"
    New-Item -Path $dirName -ItemType Directory
    Write-Host "Directory created successfully."
}

# Function to list files in a directory
function List-Files {
    $dirPath = Read-Host "Enter the directory path"
    Get-ChildItem -Path $dirPath
}

# Function to copy a file
function Copy-File {
    $sourcePath = Read-Host "Enter the source file path"
    $destPath = Read-Host "Enter the destination path"
    Copy-Item -Path $sourcePath -Destination $destPath
    Write-Host "File copied successfully."
}

# Function to delete a file
function Delete-File {
    $filePath = Read-Host "Enter the file path to delete"
    Remove-Item -Path $filePath
    Write-Host "File deleted successfully."
}

# Main program loop
do {
    Show-Menu
    $choice = Read-Host "Enter your choice (1-5)"

    switch ($choice) {
        "1" { Create-NewDirectory }
        "2" { List-Files }
        "3" { Copy-File }
        "4" { Delete-File }
        "5" { Write-Host "Exiting program..."; break }
        default { Write-Host "Invalid choice. Please try again." }
    }

    if ($choice -ne "5") {
        Read-Host "Press Enter to continue..."
    }
} while ($choice -ne "5")

This script includes:

  1. A menu display function
  2. Functions for each file management operation
  3. A main program loop that handles user input and calls appropriate functions
  4. Basic error handling for invalid user inputs
  5. Use of PowerShell cmdlets like New-Item, Get-ChildItem, Copy-Item, and Remove-Item

The script provides a simple interface for users to perform basic file management tasks, making it suitable for beginners to understand PowerShell scripting concepts and file system operations.

Dr. Scripto’s Adventures: The Mysterious Add-Computer Cmdlet

Dr. Scripto, the famous PowerShell researcher, received a strange call one day. A system administrator from a remote company desperately asked for his help:

“Doctor, please help! I need to add a hundred new computers to the domain, but traditional methods are too slow!”

Dr. Scripto smiled. “Don’t worry, my friend! I have a great cmdlet for that!”

He grabbed his magical PowerShell wand and set off on an adventurous journey. Along the way, he met his old friend, the Add-Computer cmdlet.

“Hello, Add-Computer! Ready for some action?” Dr. Scripto asked.

“Always ready, doc! What do you need?” Add-Computer replied enthusiastically.

They arrived together at the company, where the system administrator was impatiently waiting for them. Dr. Scripto introduced his new friend:

“Here’s Add-Computer! He’ll help us add the machines to the domain in a flash!”

The administrator looked at them skeptically. “Are you sure this little cmdlet can do that?”

Dr. Scripto winked and started writing the script:

$computers = Get-Content "C:\ComputerList.txt"
foreach ($computer in $computers) {
    Add-Computer -ComputerName $computer -DomainName "contoso.com" -Credential $cred -Restart
}

Add-Computer lit up and executed the command in an instant. The administrator was amazed to see all the computers join the domain.

“Incredible! You’re real wizards!” he exclaimed happily.

Dr. Scripto and Add-Computer looked at each other and laughed. “It’s not magic, it’s just the power of PowerShell!” they said in unison.

And so, Dr. Scripto and his new friend, Add-Computer, solved the mysterious domain-joining case, proving that the power within PowerShell is truly capable of wonders!

Dr. Scripto and the Regex Riddle: A PowerShell Tale

At the PowerShell Academy, excitement was always in the air, but last week’s events would go down in history as one of Dr. Scripto’s most memorable adventures. Our hero found himself face-to-face with the dreaded “Regex Monster,” and the outcome surprised everyone.

It all began on an ordinary Tuesday. Dr. Scripto was giving a lecture on advanced text processing when one of his students, the ever-curious Kriszti, raised a question: “Dr. Scripto, what if we needed to validate complex email addresses?”

Dr. Scripto’s eyes twinkled. “Ah, dear Kriszti, it’s time we delve into the wonderful world of regular expressions!”

With that, Dr. Scripto approached the board and started writing the infamous email validation regex:

^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$

The students stared at the cryptic string in bewilderment. “It… it looks like a cat walked across the keyboard!” one student remarked.

Dr. Scripto chuckled. “It might seem daunting at first, but trust me, this is one of PowerShell’s most powerful weapons!”

Over the next few hours, Dr. Scripto patiently explained each element of the regex. The students slowly began to understand the pattern’s logic, but they were still skeptical.

“But Dr. Scripto,” Kriszti spoke up, “wouldn’t it be simpler to do this in multiple steps with traditional string operations?”

“Ah, Kriszti, excellent question!” Dr. Scripto replied. “Let’s see, shall we?”

Dr. Scripto then wrote two scripts on the board. One used the regex, the other used traditional string operations. He ran both against a large list of emails.

The regex version finished in seconds. The traditional method… well, it was still running.

The students’ jaws dropped. Dr. Scripto nodded satisfactorily. “You see? Regex isn’t just accurate, it’s incredibly fast too!”

For the rest of the day, the students eagerly dove into the world of regex. They wrote patterns to check phone numbers, validate dates, and Kriszti even created a regex that could recognize Dr. Scripto’s favorite sayings in text.

At the end of the class, Dr. Scripto looked proudly at his students. “Today, you’ve not only learned to use a new tool,” he said, “but you’ve also learned a new language that can help you achieve anything in the world of text!”

As the students left the room, excitedly discussing the new possibilities, Dr. Scripto smiled to himself. “Regex is like PowerShell itself,” he mused, “intimidating at first, but immensely powerful once mastered.”

Kriszti lingered behind, her eyes shining with excitement. “Dr. Scripto,” she said, “I think I’ve fallen in love with regex!”

Dr. Scripto laughed heartily. “My dear Kriszti, welcome to the club! Remember, in the world of PowerShell, regex is like a Swiss Army knife – always handy and surprisingly versatile!”

And so, another day at the PowerShell Academy came to an end, with Dr. Scripto having successfully introduced his students to the magic of regular expressions. As he packed up his PowerShell-themed briefcase, he couldn’t help but wonder what exciting challenges tomorrow would bring.

Dr. Scripto’s Pester Adventure: A Tale of Testing Triumph

In the ever-evolving world of PowerShell, our beloved Dr. Scripto recently embarked on a thrilling journey into the realm of automated testing with Pester. This adventure not only revolutionized his approach to scripting but also brought a new level of excitement to the PowerShell Academy.

It all began on a typical Monday morning. Dr. Scripto, with his signature PowerShell-themed bowtie, burst into the classroom, his eyes gleaming with excitement. “Students,” he announced, “today we dive into the wonderful world of Pester!”

The class exchanged puzzled looks. “Pester? Is that a new type of coffee?” one student quipped.

Dr. Scripto chuckled, “Oh no, my dear pupils! Pester is far more invigorating than any caffeinated beverage. It’s a testing framework that will change the way we write and validate our PowerShell scripts!”

With that, Dr. Scripto launched into a demonstration. He pulled up a simple function on the projector:

function Get-SquareRoot {
    param($Number)
    return [Math]::Sqrt($Number)
}

“Now,” he said, his mustache twitching with anticipation, “let’s see Pester in action!”

He swiftly typed out a test:

Describe "Get-SquareRoot" {
    It "Correctly calculates square root of 16" {
        Get-SquareRoot 16 | Should -Be 4
    }
    It "Returns NaN for negative numbers" {
        Get-SquareRoot -4 | Should -Be ([Double]::NaN)
    }
}

The class watched in awe as Dr. Scripto ran the tests. Green checkmarks appeared on the screen, indicating passing tests.

“Eureka!” Dr. Scripto exclaimed. “With Pester, we can ensure our scripts work as intended, catch bugs early, and sleep soundly knowing our code is robust!”

Over the next few weeks, the PowerShell Academy was abuzz with Pester fever. Students were writing tests for everything – from simple calculator functions to complex Active Directory management scripts.

Dr. Scripto’s enthusiasm was infectious. He even started a “Pester Challenge,” where students competed to write the most comprehensive test suite for a given script.

The highlight of the Pester adventure came when the academy hosted its annual “Script-Off” competition. This year, entries weren’t judged solely on functionality but also on the quality and coverage of their Pester tests.

As Dr. Scripto awarded the trophy to the winning team, he beamed with pride. “You’ve not just written scripts,” he declared, “you’ve crafted reliable, testable, and maintainable PowerShell solutions!”

The Pester journey transformed the PowerShell Academy. Students no longer feared refactoring or updating their scripts – their Pester tests gave them confidence that nothing would break unexpectedly.

Dr. Scripto often reflected on this transformation. “Pester,” he would say, stroking his PowerShell-blue beard, “is like a faithful companion in our scripting adventures. It catches us when we fall and celebrates with us when we succeed!”

As news of the academy’s Pester proficiency spread, even industry giants took notice. Microsoft invited Dr. Scripto to speak at their next PowerShell conference about integrating Pester into development workflows.

And so, what began as a simple introduction to a testing framework became a revolution in how the PowerShell Academy approached scripting. Dr. Scripto’s Pester adventure proved once again that in the world of PowerShell, every new tool is an opportunity for growth, learning, and just a bit of scripting magic.

Remember, as Dr. Scripto always says, “In PowerShell we trust, but with Pester, we verify!”

The Evolution of PowerShell and Automation

Over the past decade, PowerShell and automation have undergone significant development, revolutionizing IT infrastructure management and system administration. This article reviews the evolution of PowerShell and the rise of automation in the IT world.

Birth and Early Years of PowerShell

Microsoft introduced PowerShell in 2006 as a combination of command-line interface and scripting language. Initially designed for Windows administrators to manage systems more effectively, PowerShell 1.0 already allowed for the automation of complex tasks and system information queries.

PowerShell Development and Expansion

Over the years, PowerShell has undergone several major updates:

  1. PowerShell 2.0 (2009): Introduced remote management capabilities.
  2. PowerShell 3.0 (2012): Significantly improved performance and expanded the range of commands.
  3. PowerShell 4.0 and 5.0 (2013-2016): Added new features such as Desired State Configuration.
  4. PowerShell Core 6.0 (2018): Platform-independent version running on Linux and macOS.
  5. PowerShell 7 (2020): Unified the best features of Windows PowerShell and PowerShell Core.

The Rise of Automation

Automation evolved alongside PowerShell:

  1. Infrastructure as Code (IaC): Enabled management of entire infrastructures through scripts.
  2. Configuration Management: Tools like Puppet and Ansible facilitated the configuration of large systems.
  3. Continuous Integration/Continuous Deployment (CI/CD): Automated software development and deployment processes.
  4. Cloud-based Automation: Cloud service APIs opened new possibilities in automation.

PowerShell in Automation

PowerShell plays a key role in automation:

  1. Scripting: Automating complex tasks with simple scripts.
  2. Modules: Extensible functionality for various systems and services.
  3. Integration: Works well with other automation tools and platforms.
  4. Cross-platform support: Enables management of heterogeneous environments.

Future Trends

The future of PowerShell and automation looks exciting:

  1. Integration of artificial intelligence into automation.
  2. Even more extensive cloud-based automation.
  3. Automation of security and compliance.
  4. Further development of PowerShell with community involvement.

The evolution of PowerShell and automation has significantly transformed the IT landscape. Today, system administrators and developers can manage complex infrastructures more efficiently, quickly, and reliably. As technology continues to advance, PowerShell and automation will undoubtedly play an even more crucial role in shaping the future of IT operations and management.