PowerShell for Office Work: 10 Small Scripts That Save Real Time

⏱ 4 min readUpdated 28 September 2026

PowerShell ships with every copy of Windows, and most office workers never open it. That is a pity, because the jobs that eat an afternoon — renaming 400 scanned invoices, merging 30 CSV exports, finding which folder is filling the disk — are one-liners here.

In this article
  1. 1. Go to a folder and look around
  2. 2. Rename files in bulk
  3. 3. Combine many CSV files into one
  4. 4. Add the source file name as a column
  5. 5. Find duplicate files
  6. 6. Which folder is eating the disk?
  7. 7. Clear Downloads older than 60 days
  8. 8. Search inside text files
  9. 9. List what is installed
  10. 10. Save a script and run it again
  11. When not to use PowerShell

Open it from the Start menu (type PowerShell). Everything below is safe to try on a copy of your files first. Commands that change things have a -WhatIf switch that shows what would happen without doing it — use it.

1. Go to a folder and look around

Set-Location "D:\Scans\March"
Get-ChildItem | Sort-Object Length -Descending | Select-Object -First 10 Name, Length

The ten biggest files in the folder. Get-ChildItem is the dir you know; the pipe | hands its output to the next command.

2. Rename files in bulk

Get-ChildItem *.pdf | Rename-Item -NewName { $_.Name -replace 'Scan_', 'Invoice_' } -WhatIf

$_ means “the current file”. Remove -WhatIf when the preview looks right. To add a date prefix instead:

Get-ChildItem *.pdf | Rename-Item -NewName { $_.LastWriteTime.ToString('yyyy-MM-dd') + ' ' + $_.Name }

3. Combine many CSV files into one

Get-ChildItem .\exports\*.csv | ForEach-Object { Import-Csv $_ } | Export-Csv .\combined.csv -NoTypeInformation

Headers are handled for you: each file is read as rows of objects, and one header is written at the end. This only works if the files share the same column names. If one export says “Amount” and another “Amt”, fix that first.

4. Add the source file name as a column

Get-ChildItem .\exports\*.csv | ForEach-Object {
    $file = $_.Name
    Import-Csv $_ | Select-Object *, @{ n = 'SourceFile'; e = { $file } }
} | Export-Csv .\combined.csv -NoTypeInformation

Now you can tell which branch or month each row came from — the first thing anyone asks when a total looks odd.

5. Find duplicate files

Get-ChildItem D:\Photos -Recurse -File |
  Get-FileHash |
  Group-Object Hash | Where-Object Count -gt 1 |
  ForEach-Object { $_.Group.Path; '' }

A hash is a fingerprint of the file’s contents, so two files with different names but identical content are caught. The script only lists them; delete by hand once you have looked.

6. Which folder is eating the disk?

Get-ChildItem C:\Users\$env:USERNAME -Directory | ForEach-Object {
    $size = (Get-ChildItem $_.FullName -Recurse -File -ErrorAction SilentlyContinue | Measure-Object Length -Sum).Sum
    [pscustomobject]@{ Folder = $_.Name; GB = [math]::Round($size / 1GB, 2) }
} | Sort-Object GB -Descending

Usually the answer is Downloads, a forgotten video export, or an OST file from Outlook.

7. Clear Downloads older than 60 days

Get-ChildItem "$env:USERPROFILE\Downloads" -File |
  Where-Object LastWriteTime -lt (Get-Date).AddDays(-60) |
  Remove-Item -WhatIf
⚠️ Remove-Item does not use the Recycle Bin. Run it with -WhatIf first, every time.

8. Search inside text files

Select-String -Path .\logs\*.txt -Pattern 'ERROR' | Select-Object Filename, LineNumber, Line

The Windows version of grep. Works on CSV and log files too.

9. List what is installed

Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* |
  Select-Object DisplayName, DisplayVersion | Sort-Object DisplayName

Handy when IT asks “which version of Office do you have?”.

10. Save a script and run it again

Paste any of these into Notepad and save as combine.ps1. The first time, Windows may refuse to run scripts. Allow scripts you wrote yourself for your own user only:

Set-ExecutionPolicy -Scope CurrentUser RemoteSigned

Then run it with .\combine.ps1 from the folder. Pair it with Task Scheduler and the job runs every morning without you.

When not to use PowerShell

If the job lives inside Excel — formatting, formulas, pivot tables — VBA or Power Query is the better tool. PowerShell is best for files, folders and anything outside a single workbook. For a comparison of options, see types of automation.

✨ Ask AI about this article

Stuck on a step? Ask a question and the AI answers using this article.

Free · AI can be wrong

Leave a Reply

Your email address will not be published. Required fields are marked *