WindowsTutorial3 min read

How to Automate Tasks with PowerShell on Windows in 2026

Learn how to write practical PowerShell scripts that automate repetitive Windows tasks — from file management to scheduled jobs and REST API calls.

Modern laptop on a desk workspace

Why PowerShell Is the Best Automation Tool on Windows

PowerShell is not just a command prompt with extra features — it is a full scripting language built on .NET with objects, pipelines, error handling, and modules. In 2026, PowerShell 7 (cross-platform) is the version to use. It ships separately from the legacy Windows PowerShell 5.1 and offers significantly better performance and compatibility.


Install PowerShell 7

If you are still on Windows PowerShell 5.1, upgrade to PowerShell 7:

winget install Microsoft.PowerShell

After installation, launch it from Windows Terminal as the PowerShell profile (not Windows PowerShell).

1 — Script Basics: Variables, Loops, and Conditions

PowerShell uses $ to prefix variables and has familiar control flow:

# Variables
$name = "Skyler"
$count = 5

# Loop
for ($i = 1; $i -le $count; $i++) {
    Write-Host "Hello $name, iteration $i"
}

# Condition
if ($count -gt 3) {
    Write-Host "Count is greater than 3"
}

2 — Automate File and Folder Operations

PowerShell makes bulk file operations trivial. Here is a script that backs up all .log files older than 7 days to an archive folder:

$source = "C:Logs"
$archive = "C:LogsArchive"
$cutoff = (Get-Date).AddDays(-7)

New-Item -ItemType Directory -Force -Path $archive

Get-ChildItem -Path $source -Filter "*.log" |
  Where-Object { $_.LastWriteTime -lt $cutoff } |
  Move-Item -Destination $archive

Write-Host "Archived old log files."

3 — Schedule a Script with Task Scheduler

You can register a PowerShell script as a scheduled task entirely from the command line:

$action  = New-ScheduledTaskAction -Execute "pwsh.exe" `
             -Argument "-NonInteractive -File C:Scriptsackup.ps1"
$trigger = New-ScheduledTaskTrigger -Daily -At "2:00AM"
$settings = New-ScheduledTaskSettingsSet -RunOnlyIfNetworkAvailable

Register-ScheduledTask -TaskName "DailyBackup" `
  -Action $action -Trigger $trigger -Settings $settings `
  -RunLevel Highest -Force

4 — Call REST APIs

PowerShell's Invoke-RestMethod handles JSON APIs with zero dependencies:

# GET request
$weather = Invoke-RestMethod "https://wttr.in/Austin?format=j1"
Write-Host "Temp: $($weather.current_condition[0].temp_F)°F"

# POST request with JSON body
$body = @{ name = "Skyler"; role = "admin" } | ConvertTo-Json
$response = Invoke-RestMethod -Uri "https://api.example.com/users" `
  -Method POST -Body $body -ContentType "application/json"

5 — Use PowerShell Modules

The PowerShell Gallery hosts thousands of community modules. Install them with Install-Module:

# Install the AWS CLI module
Install-Module -Name AWSPowerShell.NetCore -Scope CurrentUser

# Install the Excel module for spreadsheet automation
Install-Module -Name ImportExcel -Scope CurrentUser

6 — Write Reusable Functions

Wrap repeated logic in functions and dot-source them into other scripts:

function Get-DiskUsageGB {
  param([string]$Path = "C:")
  $size = (Get-ChildItem $Path -Recurse -ErrorAction SilentlyContinue |
           Measure-Object -Property Length -Sum).Sum
  return [math]::Round($size / 1GB, 2)
}

$usage = Get-DiskUsageGB -Path "C:UsersSkylerDocuments"
Write-Host "Documents folder: $usage GB"

7 — Error Handling with Try/Catch

Always wrap risky operations in try/catch so your scripts do not silently fail:

try {
  Remove-Item "C:Tempimportantfile.txt" -ErrorAction Stop
  Write-Host "File deleted."
} catch {
  Write-Warning "Failed to delete file: $_"
}

8 — Profile Script for Permanent Aliases

Add custom aliases and functions to your profile so they load in every session:

notepad $PROFILE
# Inside $PROFILE
Set-Alias ll Get-ChildItem
function gs { git status }
function gp { git push }

Next Steps

Combine these techniques to build end-to-end automation pipelines: pull data from an API, transform it with PowerShell objects, write results to Excel with ImportExcel, and email the report with Send-MailMessage. PowerShell handles the full workflow without any additional tools.