Filter Out Files With PowerShell -notlike

PowerShell's -notlike keeps text that doesn't match a wildcard pattern. To list files while leaving draft names out, filter each file's Name with Where-Object { $_.Name -notlike '*draft*' }.

Use -notlike as one operator, with no space between not and like. The asterisks mean the word can appear anywhere in the name. Start with a listing, check which files remain, and only then use that result in another command.

Try the pattern against a few names

Open a PowerShell session and try this small example. It works with text in memory, so it doesn't create or remove files:

$names = 'draft-note.md', 'final-note.md', 'photo.jpg'
$names -notlike '*draft*'

The result contains final-note.md and photo.jpg. The name containing draft is left out. Change the sample names to resemble what you're trying to filter before working with a real folder.

Drawing of a PowerShell comparison with the wildcard pattern and False result

The pattern '*draft*' has a star on each side because draft can appear at the beginning, middle or end. The pattern 'draft*' only matches text starting with draft; '*draft' only matches text ending with it.

Single quotes pass the pattern to PowerShell as written, ready to check the names. Use ordinary straight quotes in commands. Copying from formatted text can introduce curly quotes, which can make a pasted command harder to troubleshoot.

For a single name, 'draft-note.md' -notlike '*draft*' returns False. That's expected: the name matches the pattern, so the statement that it doesn't match is false. Try a nonmatching name to see True instead.

Filter file names rather than whole file records

Set the working folder to the one you're inspecting. The PowerShell folder navigation guide covers quoted paths and drive changes. Confirm the location before judging which files a listing should contain.

To list ordinary files in the current folder while excluding draft names, run:

Get-ChildItem -File | Where-Object { $_.Name -notlike '*draft*' }

The pipe sends each file to Where-Object. Inside the braces, $_ means the file being checked, and .Name selects its filename. That keeps the check on the name rather than the file's other details.

Microsoft explains how Where-Object selects records by their properties. The command displays the files that pass the test; it doesn't delete the files that fail it.

A missing result can be correct when every name matches the excluded pattern. First list the folder without the filter, then compare its names with the pattern. An empty filtered list doesn't necessarily mean the folder is empty.

This example uses -File, so subdirectories aren't included in the starting list. It also doesn't search inside file contents. Filtering filenames won't tell you which documents contain a particular word.

Choose the wildcard for what you want excluded

An asterisk matches zero or more characters. To exclude temporary filenames ending in .tmp, use '*.tmp' as the pattern. To exclude names beginning with backup, use 'backup*'.

In string comparisons, ? stands for exactly one character. For example, 'report?.txt' matches report1.txt and reportA.txt, but not report10.txt. That difference matters when a filter seems to leave some numbered files in the list.

Square brackets describe a character choice or range. The pattern 'report[12].txt' matches report1.txt or report2.txt. If your filename contains brackets, remember that a wildcard pattern gives them this special meaning.

For one exact filename, use -ne instead of a wildcard comparison: Where-Object { $_.Name -ne 'draft-note.md' }. That excludes the exact name without treating any bracket or star as a pattern character.

Choose the file detail you want to check. Name includes a file's extension. Use Extension to check just that part. FullName includes the directory path and can match a folder name you didn't intend to test.

Combine exclusions with -and

To leave out both draft names and temporary files, give each pattern its own comparison:

Get-ChildItem -File | Where-Object {
    $_.Name -notlike '*draft*' -and $_.Name -notlike '*.tmp'
}

A file remains only if both tests pass. A draft document fails the first test; a temporary file fails the second. The result is still a listing, with the original files untouched.

Don't join these two negative tests with -or when you want to leave out both kinds of file. A draft document that isn't temporary would pass the second test and remain in the list.

Also avoid placing an array of patterns on the right of a single -notlike. PowerShell treats that array as one value to compare, rather than checking each pattern separately. Write each comparison out so it's clear what you're excluding.

I'd check each pattern alone before combining them. Once each removes the intended sample names, add -and and compare the combined result. That makes a mistaken pattern easier to spot than one long expression does.

Check case and unexpected output

By default, -notlike ignores capitalization. A name containing Draft is excluded by '*draft*' too. Use -cnotlike only when capitalization needs to change whether a name passes.

What you get back depends on what you put on the left. One text value produces True or False. A collection of names produces the names that pass, so a list of filenames rather than a Boolean result is normal.

When you're filtering file objects, keep the .Name check inside Where-Object. A command can run successfully but check the wrong information, leaving you with an unexpected list.

To keep a record for review, save the PowerShell output after you've checked the filter. Leave display-formatting commands until the end if you plan to pass the file records to another command.

For an unexplained script result, send its maintainer the PowerShell version, sample names, pattern and expected/actual lists. Give them sample names without private details to use in their own check.

The Short Version

Use -notlike with a quoted wildcard pattern and test a file's Name through Where-Object. Combine separate exclusions with -and, use -ne for one exact name, and check the displayed list before passing it to another command.

Checked December 2, 2026.

If you have any business, I can build it online

Hi, I’m Hamza. I’ve been building websites and online shops for business owners since 2019, and I also built this site you’re reading.

Tell me what business you have or what you’re working on. I’ll look into how much it can grow online, and then we talk. You don’t have to buy anything or hire me first.

Chat with me on my site and I’ll show you proof of businesses I’ve helped and how they’ve grown.

Written by Isaac Smith

Isaac Smith is the founder and editor of PC Glance, a website that covers computers, laptops, and technology. He is a tech enthusiast and a computer geek who loves to share his insights and help his readers make smart choices when buying tech gadgets or laptops. He is always curious and updated about the latest tech trends.

More from Isaac Smith

Leave a Comment