Wildcard search in windows

About Wildcards

SHORT DESCRIPTION

Describes how to use wildcard characters in PowerShell.

LONG DESCRIPTION

Wildcard characters represent one or many characters. You can use them to create word patterns in commands. Wildcard expressions are used with the -like operator or with any parameter that accepts wildcards.

For example, to match all the files in the C:\Techdocs directory with a .ppt file name extension, type:

In this case, the asterisk ( * ) wildcard character represents any characters that appear before the .ppt file name extension.

Wildcard expressions are simpler than regular expressions. For more information, see about_Regular_Expressions.

PowerShell supports the following wildcard characters:

Wildcard Description Example Match No Match
* Match zero or more characters a* aA, ag, Apple banana
? Match one character in that position ?n an, in, on ran
[ ] Match a range of characters [a-l]ook book, cook, look took
[ ] Match specific characters [bc]ook book, cook hook

You can include multiple wildcard characters in the same word pattern. For example, to find text files with names that begin with the letters a through l, type:

Many cmdlets accept wildcard characters in parameter values. The Help topic for each cmdlet describes which parameters accept wildcard characters. For parameters that accept wildcard characters, their use is case-insensitive.

You can use wildcard characters in commands and script blocks, such as to create a word pattern that represents property values. For example, the following command gets services in which the ServiceType property value includes Interactive.

In the following example, the If statement includes a condition that uses wildcard characters to find property values. If the restore point’s Description includes PowerShell, the command adds the value of the restore point’s CreationTime property to a log file.

Mimic windows wildcard search using PowerShell script

got an requirement to find whether document has any ip address in it. do we have any PowerShell script/command to do it for any file type. I found few script which works only for .txt files.

1 Answer 1

In order to search for an IP address in any file type, you need to solve two basic problems.

One, PowerShell needs to perform searches against the contents of any file type.

Two, the search needs to define an IP address.

For the first problem, it is possible to search the contents of common file types using Windows Search. However, Windows Search does not have a practical way of searching for an IP address. It is good at searching for human-readable text like «apple pie». It does not have useful wild card or declarative syntax that would be suitable for IP addresses. You’d be better off searching for «IP address» as far as Windows Search is concerned.

For the second problem, there are many strings which could qualify as an IP address:

  • 172.16.0.1
  • 192.0.2.0/24
  • 10.x.x.x
  • 2001:0db8:0000:0000:0000:8a2e:0370:7334
  • 2001:db8::8a2e:370:7334

Typically, developing a solution would start with defining an appropriate regular expression. You can find some help online. But it would take work to cover everything that qualifies as «any ip address».

The scenario you are describing is commonly known as eDiscovery. You might search for a product that will do what you ask.

So that others can benefit from my research, here is a working example using Windows Search in PowerShell. Here, I search for PowerShell in the C:/Users/Michael/Stack Overflow directory. Notice the search term is relatively simple which is a limitation of the full-text search.

Make sure to scroll down and copy the whole script.

Take care to note that «mimic windows wildcard search» refers to the file name in practice. I’m not aware of a way to use wild cards against the body of a document except a trailing asterisk like this:

Wildcard search in windows

This forum has migrated to Microsoft Q&A. Visit Microsoft Q&A to post new questions.

Asked by:

Question

1.
How can I use File Explorer Search to search in content using wildcards?

Having the files (the location is indexed):
text1.txt
art work

I want to find the ‘work’ in text2.txt

The following search terms do not find it:
*work
content:*work
content:»*work»
content:

All replies

You can refer to the link below, it may apply to Windows 8.

Advanced tips for searching in Windows:

While I don’t think the key works search in text, office, web are same with Windows Explorer. They are two different search types.

In addition, as we know, in a text file, it can had many same words such ”work”, while in a folder, it couldn’t had multiple same files.

Roger Lu
TechNet Community Support

the link you pointed to does not help solving the problem.

My initial post shows easy steps to reproduce the problem. Please try yourself.

Actually, I made a try follow your steps, it does had the problem as you said. I didn’t find any document about Windows File Explorer Search syntax except the link above.

But, I think we could find a reasonable explanation for your problem. As we know, the search syntax «*work» means to search all the file that had a key word «work» no matter any letters before «work». While in Text file, the search system would take it as you would like to search a letter that named «*work». The both are different,

Roger Lu
TechNet Community Support

As we can only find documentation about Windows 7 search please ask the team that developed search to supply documentation for File Explorer search in Windows 8.1. Especially describing how content search is meant to be used.

For lots of related search problems that still may or may not exist see Windows 7 search — does not return file contents — continued.

Where is the File Explorer search syntax documented by Microsoft?

You have the right syntax. Windows Search from File Explorer is FUBAR. Use right-click Edit Address to see how badly.

What we need is some documentation about any diagnostics that exist for it (faint hope?) to try to figure out how to work around all of the apparent defects in order to try to make it less irritating to try to use.

Otherwise, you can look for third-party solutions which are more usable, more functional and a better place to invest your time learning to master.

Might be a bit late however you can use content:

=»work» or content:

«work» to find it! Basically you can use the provided syntax to even search for space separated string e.g. a file containing «work work» can be found with content:

=»work work» (exact match). I know that this doesn’t exactly solve your wildcard issue however your underlying problem should be solved.

The AQS documentation isn’t that great and I also found this solution somewhere else but it might be a lifesaver. also it doesn’t depend on 3rd party software. If you already found a solution it might help future Googlers.

Alternatively you can also use contents: instead of content: .

Can I use wildcards in Windows 8 search?

When using a new Windows 8 search bar:

What is the syntax of the search expression? Is it possible to use wildcards like «*», «?» or any other special symbol?

For example, when searching with Google i can use:

  • ‘ (minus) for excluding certain words;
  • «quoted phrase» for exact phrase matching.

3 Answers 3

Windows 8 has a number of search features.

It supports two wildcards.

You can search by:

You can still search using the Advanced Query Syntax.

I recommend reading the article because there are a lot of features.

Here are some of the boolean operators:

I guess you should be able to use the same wildcard codes that were usable in Windows 7 since the «type to search» feature is nearly identical in both. Here’s a link that describes some of the codes. It describes wildcards and search codes.

An extract from the site

This option has been with us since the earliest days of DOS and Windows and consists of two wildcards: ‘?’ and ‘’ (without the single quote marks). The simplest explanation to what the two different wildcards do boils down to this: the ‘?’ means one character appears here and the ‘’ can stand for any number of characters – letters or numbers.

So if you are using the ‘?’ and you are searching for a file that you know part of the name of your query could look like this fo??t which would return any file that started with fr and ended with a ‘t’ but only had two unknown letters in the middle. In this case the file foxit could be one of the search results.

When using the ‘*’ as part of the search term it is best to use it either at the beginning of the word – it – or in the middle – ft – in either case the file named foxit would be returned as part of the results. As for using the ‘*’ wildcard at the end of the search term there isn’t much of a point because Windows search always acts like there is a wildcard at the end.

Search Codes

The one thing about the way I usually end up doing searches is that I typically end up with way more results than I really need. The way around this happening is to use search shortcuts – or codes – to further refine what you are searching for.

The simplest of these is the document types short codes. For example you are searching for a specific image but you forget its name but remember that it is a JPEG (jpg) image. In this case you can use the following short codes to refine your search

Wildcard search in windows

Вопрос

I am reading information from first root level folder. I have some folders like Windows PowerShell, Meetings_02072007, BKUP_02, BKUP_01, BKUP, Backup_2015, BackUP_2016, Old_Backup, Backups.

So I created variable $ignoreFolders where I put the folder name as

Now I am checking folders like below, but it not detecting any of the folders, Let me know what is the problem here

Ответы

Все ответы

$foldersToExclude = «$skippedDirName,shell,Appdata,Personal_Settings» -split ‘,’
Get-ChildItem

Thanks for reply. I just made some correction in variable in my original post. Please guide me in following line to improvise

#Skip folders in the Ignore List if any
if($foldersIgnore -and $foldersIgnore -contains $currentFolder) <
return $True
>

It is working if FolderName contains exactname.

Can anyone advise me on above code?

Can anyone advise me on above code?

I posted the correct method above.

I made changes the folder names in $foldersToExclude now code looks like

$foldersToExclude= «$skippedDirName,BackUp,BKUP,shell,Appdata,Personal_Settings» -split ‘,’
Get-ChildItem

I have some folders like like BackUp2017 or BackUpJanuary or BKUP0102 or BKUP1216. Above code is not detecting these folders. Above code is exact match nor like or contain match. I want to do it like or contains or in nutshell wildcard. I mentioned same problem in my initial post as well.

Читайте также:  Remove empty files linux
Оцените статью