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:
$file = Get-Item -Path C:\Reports\sales-2026-10.csv
$file.Extension # .csv
$file.BaseName # sales-2026-10
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 file extension in PowerShell and the name without it, using Get-Item, .NET and Split-Path. I’ll also cover the edge cases and the PowerShell 7 vs 5.1 differences I hit while testing.
Get the file extension and base name with Get-Item
Get-Item returns a FileInfo object. Its Name, Extension and BaseName properties split the file name for you:
$file = Get-Item -Path .\Reports\sales-2026-10.csv
"Name: $($file.Name)"
"Extension: $($file.Extension)"
"BaseName: $($file.BaseName)"
Output:
Name: sales-2026-10.csv
Extension: .csv
BaseName: sales-2026-10

Notice that Extension includes the leading dot. Get-Item fails when the file doesn’t exist, so check the path with Test-Path first when you aren’t sure.
Get the extension from a path string with GetExtension
The .NET Path class only reads the text, so the file can be missing, on another PC or not created yet:
$path = 'C:\Reports\2026\invoice-7001.pdf'
[System.IO.Path]::GetExtension($path)
[System.IO.Path]::GetFileNameWithoutExtension($path)
"README: [$([System.IO.Path]::GetExtension('C:\Reports\README'))]"
Output:
.pdf
invoice-7001
README: []
A name with no extension gives an empty string, not an error. These methods pair well with getting the file name from a full path when you parse log lines or CSV columns.
Split-Path -Extension and -LeafBase in PowerShell 7
PowerShell 6 added two switches to Split-Path: -Extension returns the extension and -LeafBase the name without it. Windows PowerShell 5.1 doesn’t have either:
$path = 'C:\Reports\sales-2026-10.csv'
try {
Split-Path -Path $path -Extension -ErrorAction Stop
Split-Path -Path $path -LeafBase -ErrorAction Stop
}
catch { "Failed. $($_.Exception.Message)" }
Output:
.csv
sales-2026-10
That output is from PowerShell 7. Here’s what 5.1 printed for the same script:
