Courses/PowerShell/Automation and Task Scheduling

    Automation and Task Scheduling

    Schedule scripts, manage remote computers, and automate repetitive admin tasks.

    What You'll Learn

    • Creating and managing scheduled tasks from PowerShell
    • PowerShell Remoting (Invoke-Command, Enter-PSSession)
    • CIM/WMI queries for system information
    • Real-world automation scripts for daily tasks

    Task Scheduling

    Windows Task Scheduler can be fully controlled from PowerShell โ€” no GUI needed. You define three things: what to run (Action), when to run (Trigger), and how to run (Settings).

    # Create a nightly backup task
    $action = New-ScheduledTaskAction -Execute 'pwsh.exe' `
        -Argument '-File C:\Scripts\backup.ps1'
    $trigger = New-ScheduledTaskTrigger -Daily -At '2:00AM'
    
    Register-ScheduledTask -TaskName 'NightlyBackup' `
        -Action $action -Trigger $trigger -User 'SYSTEM'

    ๐ŸŽฏ Real-World Analogy: Think of Task Scheduler as a reliable assistant who wakes up at the exact time you specify and runs your to-do list without supervision.

    โš ๏ธ Common Mistake

    Scheduled tasks run in a non-interactive session โ€” there's no console to see output. Always log results to a file: | Out-File C:\Logs\backup.log -Append. Also set -StartWhenAvailable so missed runs execute when the machine wakes up.

    Scheduled Tasks

    Create and manage scheduled tasks from PowerShell.

    Try it Yourself ยป
    JavaScript
    // PowerShell Automation โ€” simulated in JavaScript
    console.log("=== Scheduled Tasks ===");
    console.log();
    console.log("Create scheduled tasks directly from PowerShell:");
    console.log();
    console.log("$action = New-ScheduledTaskAction \\");
    console.log("    -Execute 'pwsh.exe' \\");
    console.log("    -Argument '-File C:\\Scripts\\backup.ps1'");
    console.log();
    console.log("$trigger = New-ScheduledTaskTrigger \\");
    console.log("    -Daily -At '2:00AM'");
    console.log();
    console.log("$settings = New-Sc
    ...

    Remoting & System Queries

    PowerShell Remoting lets you run commands on remote machines as if you were sitting at them. Enable it with Enable-PSRemoting on the target, then use Invoke-Command:

    # Run on one machine
    Invoke-Command -ComputerName Server01 -ScriptBlock {
        Get-Service | Where Status -eq Running | Measure
    }
    
    # Run on multiple machines simultaneously
    Invoke-Command -ComputerName Server01,Server02,Server03 {
        Get-CimInstance Win32_OperatingSystem | Select Caption, FreePhysicalMemory
    }

    CIM (Common Information Model) replaces the older WMI interface. Use Get-CimInstance to query hardware, OS, disk, network, and software information:

    # Disk space report
    Get-CimInstance Win32_LogicalDisk | Select DeviceID,
        @{N='FreeGB'; E={[math]::Round($_.FreeSpace/1GB, 2)}},
        @{N='TotalGB'; E={[math]::Round($_.Size/1GB, 2)}}

    Remoting & CIM

    Remote management and system information queries.

    Try it Yourself ยป
    JavaScript
    // Remote Management & CIM โ€” simulated in JavaScript
    console.log("=== PowerShell Remoting ===");
    console.log();
    console.log("Run commands on remote computers:");
    console.log();
    console.log("  # Enable remoting (run as Admin on target)");
    console.log("  PS> Enable-PSRemoting -Force");
    console.log();
    console.log("  # Run command on remote machine");
    console.log("  PS> Invoke-Command -ComputerName Server01 -ScriptBlock {");
    console.log("      Get-Service | Where Status -eq Running");
    console.log(" 
    ...

    ๐Ÿ’ก Pro Tip

    Combine PowerShell Remoting + Scheduled Tasks for enterprise automation: create a script that runs Invoke-Command on all your servers, then schedule it daily. You can manage an entire data centre from one machine.

    ๐Ÿ“‹ Quick Reference

    CmdletPurpose
    Register-ScheduledTaskCreate a scheduled task
    Invoke-CommandRun commands on remote machines
    Enter-PSSessionInteractive remote session
    Get-CimInstanceQuery system hardware/software
    Send-MailMessageSend email alerts
    Start-JobRun script in background

    ๐ŸŽ‰ Course Complete!

    Congratulations! You've completed the entire PowerShell course โ€” from basic cmdlets to enterprise automation. You're now equipped to automate Windows administration, manage servers remotely, and build production scripts.

    Sign up for free to track which lessons you've completed and get learning reminders.

    Cookie & Privacy Settings

    We use cookies to improve your experience, analyze traffic, and show personalized ads. You can manage your preferences below.

    By clicking "Accept All", you consent to our use of cookies for analytics and personalized advertising. You can customize your preferences or reject non-essential cookies.

    Privacy Policy โ€ข Terms of Service