Vijay_Wiki
/ Computing and IT for engineers / PowerShell

PowerShell for Engineers: Files, Inventory, Backups and Safe Automation

K Vijay Anand · Vijay_Wiki quick-reference article · 24 November 2026
PowerShellWindowsAutomationScripting

PowerShell ships with every modern Windows PC and is the quickest way to automate repetitive admin on lab and office machines: listing what is installed, finding large or duplicate files, backing up data folders, and scheduling jobs. Its key difference from the old command prompt is that commands pass objects, not text, so filtering and sorting are reliable.

Key takeaways

  • Commands are Verb-Noun cmdlets (Get-ChildItem, Copy-Item); Get-Help and Get-Command find what you need.
  • The pipeline passes objects: Get-ChildItem | Where-Object Length -gt 1GB | Sort-Object Length.
  • Find duplicates reliably by grouping on Get-FileHash, not on names or sizes alone.
  • Use robocopy for robust backups and mirrors, with logs and retry limits.
  • Work safely: test with -WhatIf, log with Start-Transcript, stop on errors with try/catch and -ErrorAction Stop, never delete before checking.

1. Basics

TaskCommand
Help on a commandGet-Help Get-ChildItem -Examples
Find commandsGet-Command *Item*
See object propertiesGet-ChildItem | Get-Member
FilterWhere-Object { $_.Length -gt 100MB }
Sort and pickSort-Object Length -Descending | Select-Object -First 20
ExportExport-Csv report.csv -NoTypeInformation
Allow local scripts (current user)Set-ExecutionPolicy -Scope CurrentUser RemoteSigned

2. Files: large, old and duplicate

# 20 largest files under D:\Data
Get-ChildItem D:\Data -Recurse -File -ErrorAction SilentlyContinue |
  Sort-Object Length -Descending | Select-Object -First 20 FullName, @{n='MB';e={[math]::Round($_.Length/1MB,1)}}

# Files not modified for 2 years (report only)
$cut = (Get-Date).AddYears(-2)
Get-ChildItem D:\Data -Recurse -File | Where-Object LastWriteTime -lt $cut |
  Export-Csv old_files.csv -NoTypeInformation

# Duplicates by content hash (size first, then hash only same-size files)
Get-ChildItem E:\ -Recurse -File | Group-Object Length | Where-Object Count -gt 1 |
  ForEach-Object { $_.Group | Get-FileHash -Algorithm SHA256 } |
  Group-Object Hash | Where-Object Count -gt 1 |
  ForEach-Object { $_.Group | Select-Object Hash, Path } | Export-Csv duplicates.csv -NoTypeInformation

3. System inventory

$cs = Get-CimInstance Win32_ComputerSystem
$os = Get-CimInstance Win32_OperatingSystem
[pscustomobject]@{
  Name = $cs.Name; Model = $cs.Model; RAM_GB = [math]::Round($cs.TotalPhysicalMemory/1GB,1)
  OS = $os.Caption; Build = $os.BuildNumber; Arch = $os.OSArchitecture
} | Export-Csv inventory.csv -NoTypeInformation

# Installed programs (registry, faster and safer than Win32_Product)
$keys = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*',
        'HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'
Get-ItemProperty $keys | Where-Object DisplayName |
  Select-Object DisplayName, DisplayVersion, Publisher | Sort-Object DisplayName |
  Export-Csv installed.csv -NoTypeInformation

Get-PnpDevice -PresentOnly | Select-Object Class, FriendlyName, Status | Export-Csv devices.csv -NoTypeInformation

4. Backups with robocopy

# Mirror D:\TestData to a backup drive, retry once, log everything
robocopy D:\TestData F:\Backup\TestData /MIR /R:1 /W:1 /FFT /NP /LOG+:F:\Backup\robocopy.log
# /MIR deletes files at the destination that no longer exist at the source - check the path twice.
SwitchMeaning
/ECopy subfolders including empty ones
/MIRMirror (= /E + delete extras at destination)
/R:n /W:sRetry count and wait between retries
/XOExclude older files (incremental)
/MT:16Multi-threaded copy
/LList only — dry run
/LOG+:fileAppend to a log file

5. Scheduling

$act = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument '-NoProfile -File C:\Scripts\backup.ps1'
$trg = New-ScheduledTaskTrigger -Daily -At 23:30
Register-ScheduledTask -TaskName 'Nightly data backup' -Action $act -Trigger $trg -RunLevel Highest

6. Safe habits

7. Calculators

Command builder

Fills in a tested pattern with your paths. Review the command before running it; robocopy /MIR deletes extra files at the destination.

8. Self-test: check your understanding

Pick an answer to see the explanation. Numerical answers are accepted within the stated tolerance (±3 % unless noted).

Score

9. References and further reading

  1. Microsoft Learn, PowerShell documentation (about_Pipelines, about_Try_Catch_Finally, Get-FileHash, Get-CimInstance).
  2. Microsoft Learn, robocopy command reference.
  3. Jones, D. and Hicks, J., Learn PowerShell in a Month of Lunches, 4th ed., Manning, 2022.

Web pages

Disclaimer

This article is for education and quick reference. Formulas are simplified first estimates and examples use typical data. For design, safety and maintenance decisions use manufacturers' data and the applicable standards.

Related Vijay_Wiki articles