Learn about Windows PowerShell
Summary: Microsoft PFE, Gary Siepser, shares a cool Windows Search trick to find Windows PowerShell scripts.
Microsoft Scripting Guy, Ed Wilson, is here. Today our guest blogger is Gary Siepser. Here is Gary to tell us about himself:
I am a premier field engineer(PFE) in the Customer Services and Support(CSS) part of Microsoft Services. Wow, I know that is a mouthful, so let me lay it out a little more simply. I am a field engineer who helps premier support customers in getting the most of their Microsoft infrastructure. There are several flavors of PFEs, but I am what we refer to as "transactional,” and I work with many customers with a limited technology focus. I used to be a messaging PFE and support Exchange Server (I even managed to become a Microsoft Certified Master in Exchange 2007), but I have morphed over to 100% Windows PowerShell support engagements with our customers. These engagements are mostly delivering premier workshops.
Note: If you are premier customer, we have some great Windows PowerShell instructors and workshops, so talk to your technical account manager (TAM) to find out more. If you are not a premier customer, why not?
I also work with our customers beyond workshops, such as custom-scoped, onsite Windows PowerShell knowledge transfer. This is typically built around a scripting need that a customer has, and I provide knowledge transfer and sample solutions to help customers solve those needs. When I am not working with customers, I am the U.S. PowerShell tech lead within our PFE organization, and I focus a lot of attention on IP development, internal readiness, Train-the-Trainer (TTT) delivery and instructor recruitment, and generally promoting Windows PowerShell throughout PFE and by proxy to our customers.
Blog: Gary's $this and that about PowerShell and Exchange
You can use Windows Search to easily find your scripts by searching for anything in the scripts. This post covers a simple topic, but it is an important one that is helpful to me, and hopefully to you. First of all, old versions aside, I think that Windows Search in Windows 7 works really well. It is very fast at finding files, documents, communications (like emails), and more. Let us focus on using it to help find Windows PowerShell scripts.
Windows Search will also find your scripts if you have you have them stored in a location that it is indexing. You can see the indexed locations on your Windows 7 computer by looking in the Control Panel under Indexing Options. The first thing we want to do is ensure that our scripts are in a location that is set up to be indexed. The screenshot below shows the main Indexing Options window and the Indexed Locations window that pops up when you click the Modify button on the initial window.
You can see that you can set what locations are indexed by simply checking the box next to the folder in the tree view. You will find the most common locations where Windows intends for you to store files that are already indexed (such as your user profile folders). I normally keep my documents and user files in the profile folders where I think Windows expects them. However, in the case of my scripts, I break my normal rule and I store them in a folder on my secondary hard drive (D:). I ensure that the location in my D drive is selected. I would suggest that you select the locations where you keep any files you want to be able to more easily find (like your scripts folder if it is not already selected).
Ensuring that your scripts folder is indexed is valuable, but it is only a piece of the “hotness.” The real key is to now tell Windows Search to index the actual contents of your Windows PowerShell scripts. Yes, that means Windows Search will read your scripts and let you search (very quickly) for anything in your scripts (think a function or cmdlet name).
To set this, you need to get a little deeper into the indexing options. You need to click the Advanced button on the main window. If you use user account control (UAC) and depend on its settings, you might have to approve the security prompt.
When the new Advanced Options window opens, click the File Types tab. On this tab, you want to ensure that you tell Windows Search to index the properties and file contents of your scripts. This most certainly means .ps1 files, and I would also include .psm1 and .psd1 files to cover script modules and the module manifest respectively.
In the following screenshot, I have highlighted the three lines where I edited the default settings of the properties, and I have them set to Plain Text Filter (which is the Index Properties and File Contents radio button when each file extension is selected). When you OK the change, Windows Search will rebuild your index (it takes a little time, but it’s a background task that is respectful of activity on your system).
When your index is up-to-date with the locations and file contents of your scripts, you can find your scripts easily. You can leverage the search in many places; for example, on the main Start menu or when a file window is open (like in the following ISE open file window). Now you can search on anything in the scripts. For example, you could search on a cmdlet name and easily see which scripts contain that cmdlet. Or you could search on some particular comments that you add to your scripts. Of course, some folks have better “Search Kung Fu” than others, so your mileage may vary. In the following screenshot, I show how I can leverage the search when I am trying to open a script through the Windows PowerShell ISE.
In the previous screenshot, you can see that I typed export-csv as my search string (highlighted in yellow). The results include scripts that do not have that in their name, but it appears in their content. This trick really helps me almost on a daily basis because I do not focus intently on how I name my scripts or how I organize my script folders.
With this feature, I am able keep a flat folder structure with only a few folders, but the bulk of my scripts are stored in my main scripting folder. I hope this tip helps you—it really has made a difference for me. Unfortunately, every time I upgrade to a new machine or reinstall Windows, I have to reset these settings. I guess these setting must not transfer with Windows Easy Transfer because I use that tool.
Thank you, Gary, for sharing a very useful tip to help to manage Windows PowerShell scripts.
I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at email@example.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.
Ed Wilson, Microsoft Scripting Guy
Gary! Sweet tip! It is amazing to see just far the Power of Shell can be extended to in Windows!
"The Energized Tech"
it's quite interesting to see, what we could do with windows tools, thatare already "on board" and we only might have neclected them or haven't realized the power inside :-)
Well ... thanks for pointing that out!
A merry christmas!
Great tip! Wish I would have thought of this years ago!