So you just finished writing some code and you go to save your file. You summarize all of the important aspects this section of code contains into a nice, easy-to-read file name that your future self will immediately recognize. Fast forward to the future where you haven’t the foggiest clue what your youngerself was thinking and you can’t seem to find that file you so desperately need. Hope fades as your search for what you might have called the file, yielding no results. But comrades, it doesn’t have to be this way! You can actually index scripts for Windows Search to prevent this painful process.

\\\Guess Who

If you save your files in a common location, then your saved files should be indexed. So searching by name will usually get you what you’re looking for. But what if you want to find a line in your code? Or how many of your scripts use a specific command? Unfortunately, this doesn’t happen out of the box in Windows. The default for most file types is only to filter on properties. However, it only takes a quick few clickety-clicks to change your life forever by searching the content of your code and not just the properties. So without further ado, let’s do this thing!

You can get there several ways, but by far the easiest is to click in that search bar/press your Windows Key on your keyboard and just type “Index”. If you typed these five letters correctly, you should see Indexing Options. And on a side note, this is assuming you’re using Windows 10/11…for all my Vista fellas your mileage may vary. You could also go to Windows Settings > Search > Searching Windows > Advanced Search Indexer Settings.
Indexing Scripts - Windows Indexing Options

\\\Options Trading

Before we go any further, if your files are saved outside of the common locations like Documents, Desktop, or almost anywhere else in your user profile, you’ll want to add it. First, click “Modify” to see the current directories being indexed. Browse to your code directory, check the box, and then click “Ok.” It’s easier than extending your vehicle warranty.

Indexing Scripts - Modify Locations

Now that we have our locations indexed, we want to change the filter on our specific file types. To begin, click “Advanced” and then click the “File Types” Tab. For Python, look for .py. For PowerShell, look for .psm1, .ps1, .ps2, ps3. ps4…maybe not those last PlayStations, but you catch my drift. Highlight each file type you want to be able to search the contents of and then click the “Index Properties and File Contents” bubble. When you’re finished, click “Ok” to save your changes.

Indexing Scripts - Change to filter content

\\\but does it actually work???

Like all good IT scientists, we empirically validate our experiments before we start flapping our gums and fire off emails claiming “we’ve found the issue!” Open up Windows Explorer and in the top right search bar type in your deepest darkest secret line you want to find. As an example, I’m going to search for a variable I used in the post about Quickly Testing APIs in PowerShell. Let’s see if we do in fact have the Midas touch.

Indexing Scripts - Search for content in script

And that’s that! This was easier than falling off the edge of the flat Earth and getting eaten by a turtle. Since you have indexed your scripts for Windows Search, you can now easily search any of the contents of your scripts/code. Gone are the days for extremely long file names or making your own cheat sheets of what’s in each of your files. Go rest now from all of your arduous labor.


Nested AD Managers (PowerShell)

So I had a somewhat odd request (isn't that how all truly great stories start) a long time ago in an IT galaxy far, far away. And it went something like this: we want to email an employee and CC their manager, but if their manager is inactive (took a one-way trip to...

6 Things I Wish I Had Known About PowerShell

About a hundred years ago when I stopped riding dinosaurs to work and started learning PowerShell, I struggled to know what to learn first and where to even begin. That blue box with white writing was intimidating to say the least. I finally worked up the courage to...

Array vs ArrayList (PowerShell)

For some tasks in life, being precise is a necessity. But most of us get away with rounding, paraphrasing, and hitting in the general vicinity most of the time. Depending on your personality, you may be one who strives for perfection and strains on every miniscule...

Spice Up HTML Emails with PowerShell – Part III

So far in this series we've fumbled our way around the kitchen and tried to wing it when sending HTML emails with PowerShell. It was clunky to say the least. We then went through our spice rack and built an HTML template, highlighting the nuances of each spicy element...

Spice up HTML Emails with PowerShell – Part II

In Part I of our scrumptious concoction we put our script into the oven to let it bake. But we forgot to add our secret sauce that's sure to leave our recipients drooling, which is clearly our goal. In this post we'll continue to spice up HTML emails with PowerShell...