How to Run a PowerShell Script at Startup in Windows

Run a PowerShell script at startup in Windows

You want a script to map drives or log a health check every time Windows starts, without anyone remembering to run it. Quick answer: to run a PowerShell script on startup, register a scheduled task with a logon trigger that starts powershell.exe with your script: In this tutorial, we’ll run a PowerShell script on startup … Read more

How to Write to the Windows Event Log with PowerShell

Write to the Windows Event Log with PowerShell

To write to the event log with PowerShell, register an event source once as administrator, then send entries with Write-EventLog: In this tutorial, I’ll build that logging into a real backup script, step by step, so you can write to event log PowerShell entries that your monitoring tools pick up. Our example admin is Maria … Read more

How to Change File Extensions with PowerShell

Change file extensions with PowerShell Rename-Item

To change a file extension in PowerShell, rename the file with Rename-Item and give it the new name, extension included: Output: In this tutorial, I’ll show you how to change file extensions with PowerShell for one file, a whole folder and its subfolders, plus two traps I hit while testing in PowerShell 7 and 5.1. … Read more

Update-Module: Update PowerShell Modules

Update-Module updating a PowerShell module with the old version kept side by side

A Spectre patch check on our Austin office PCs kept giving stale answers, and the cause was an old module. Update-Module in PowerShell pulls the newest version of a module you installed from the PowerShell Gallery: In this tutorial, I’ll show you how Update-Module in PowerShell really behaves: checking for updates, pinning versions, updating everything, … Read more

How to Clear Event Logs with PowerShell (Clear-EventLog)

Clear event logs with PowerShell: backing up the Windows PowerShell log before clearing it

To clear event logs with PowerShell, open the console as administrator and run Clear-EventLog with the log name. It wipes every entry in that classic log: In this tutorial, I’ll show you how to clear event logs in PowerShell safely: check their size, preview with -WhatIf, back them up, then clear one log, every log … Read more

Start a Windows Service with PowerShell (Start-Service)

Start a service with PowerShell: a Start-ServiceChecked morning check previewing the services with -WhatIf

Run Start-Service with the service name from a PowerShell window opened as administrator, and Windows starts it. That’s how you start a service with PowerShell: Dana Reyes looks after 20 PCs at an architecture firm in Austin. A few mornings a month, a service that should be running isn’t, and the first sign is a … Read more

Stop a Windows Service with PowerShell (Stop-Service)

Stop a service with PowerShell: Stop-Service previewing the Print Spooler stop with -WhatIf

A print queue is stuck, an update wants a service out of the way, or a misbehaving agent is eating CPU. You need that service stopped now, and you’d rather not click through the Services console. Quick answer: to stop a service with PowerShell, run Stop-Service with the service name in a window opened as … Read more

PowerShell Continue Statement in Loops (With Examples)

PowerShell continue statement skipping orders in a foreach loop

To use continue in a PowerShell loop, put it inside an if test. When the test is true, PowerShell skips the rest of that pass and moves to the next item: Output: In this tutorial, I’ll show you how continue in a PowerShell loop works in foreach, for, while and do loops, plus the switch … Read more

PowerShell Boolean Values ($true and $false)

PowerShell Boolean values $true and $false explained with tested examples

A settings file once told my script SendEmail = False, and the email went out anyway. A PowerShell Boolean is only $true or $false; the text ‘False’ is just a non-empty string: In this tutorial, I’ll show you how a PowerShell Boolean works: the [bool] type, which values count as true, -not and -and, [switch] … Read more

Out-Host in PowerShell: Paging, Write-Host and Late Tables

Out-Host in PowerShell explained with tested examples

Out-Host in PowerShell sends objects straight to the console window and returns nothing to the pipeline. You’ll reach for it to page long output or to make a table print right now instead of later: In this tutorial, I’ll show you how Out-Host in PowerShell compares with Write-Host, Write-Output and Out-Default, how -Paging behaves, and … Read more