How to Get Yesterday’s Date and Add Days to a Date in PowerShell

Get yesterday's date in PowerShell with AddDays

To get yesterday’s date in PowerShell, subtract one day from today with (Get-Date).AddDays(-1). The same AddDays() method adds days to any date, and a negative number goes back in time: Output: I pinned the examples to fixed 2026 dates so your output matches mine. In a real script, start from Get-Date instead, and the results … Read more

Import-Csv in PowerShell: Read CSV Files and Loop Through Rows

PowerShell Import-Csv reading a CSV file into objects

Import-Csv is the PowerShell cmdlet that reads a CSV file and turns every row into an object. The column headers become property names, so you can sort, filter and loop through the data without parsing text: Output: The file customers.csv holds four US customers with the columns Id, Name, Company, State and Total. I use … Read more

Get-Service in PowerShell: List Running Services and More

Get-Service in PowerShell: list running services and filter them

Get-Service is the PowerShell cmdlet that reads the Windows services on your PC. On its own it lists every service; pipe it to Where-Object to list only the running ones. Here I check a set of standard Windows services: Output: Without -Name, Get-Service returns every service on the PC. I kept the examples to built-in … Read more

Echo in PowerShell: How Write-Output Works (With Examples)

Echo in PowerShell and Write-Output cmdlet examples

You type echo in PowerShell out of CMD or Bash habit, and it mostly works. Then a sentence splits across three lines, or echo -n does nothing you expected. Quick answer: echo is a built-in alias for Write-Output. It sends objects to the success stream (the pipeline). If nothing consumes them, they’re shown in the … Read more

PowerShell Escape Character (Backtick): Escape Special Characters

PowerShell escape character (backtick) examples

The PowerShell escape character is the backtick (`), the key just below Esc on a US keyboard. Inside double quotes, a backtick makes the next character literal, like `$, or turns it into a special character, like `t for a tab: Output: A backslash is just a normal character in PowerShell, so Windows paths need … Read more

Create a Directory in PowerShell with New-Item (and mkdir)

Create a directory in PowerShell with New-Item

Creating a directory in PowerShell takes one command: New-Item -Path C:\Reports -ItemType Directory. Change the item type to File and the same cmdlet creates a file. Here are both in one script: Output: New-Item hands back the new item, a DirectoryInfo for a folder and a 0-byte FileInfo for a file, so you can use … Read more