How to Get a File Extension in PowerShell (and the Name Without It)

Get a file extension and the file name without extension in PowerShell

Every file object PowerShell hands you already knows its extension. Read the Extension property to get the file extension, and BaseName for the file name without the extension: For a path that’s only text, [System.IO.Path]::GetExtension() and GetFileNameWithoutExtension() do the same job without touching the disk. In this tutorial, I’ll show you how to get a … Read more

How to Import an Excel File in PowerShell (and Read It into an Array)

Import an Excel file in PowerShell and read it into an array

To import an Excel file in PowerShell, install the ImportExcel module and run Import-Excel. It reads the first worksheet into an array, one object per row, with the header row as property names: If Excel is installed and you’d rather skip the module, the Excel COM object gives you a two-dimensional array through UsedRange.Value2. I … Read more

How to Check If a PowerShell Module Is Installed (and List Modules)

Check if a PowerShell module is installed and list installed modules

Need to check if a PowerShell module is installed? Run Get-Module -ListAvailable -Name with the module’s name. It returns the module when it’s installed and nothing when it isn’t, so it drops straight into an if: Leave out -Name and the same command lists every installed module. Below I’ll cover both jobs, plus versions, gallery … Read more

Capitalize the First Letter in PowerShell (Plus Uppercase, Lowercase and Title Case)

Capitalize the first letter and convert case in PowerShell

To capitalize the first letter in PowerShell, uppercase the first character and add the rest of the string back: $text.Substring(0, 1).ToUpper() + $text.Substring(1). For the whole string, call .ToUpper() or .ToLower(), and for every word, use ToTitleCase: Output: None of these change $city itself. Each one returns a new string, so save the result in … Read more

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