I saw a tweet from June Blender a few days ago that I thought was interesting:
I knew you could use Select-String for searching documents like this but it’s not something that I knew the exact syntax for off the top of my head. It’s something that would have taken me at least a few minutes to figure out, probably with a little trial and error.
It just so happens that a few days later, I was looking for how I had done something with the range operator in one of my PowerShell scripts. Manually looking for this through thousands of scripts I’ve saved wouldn’t have been worth the effort, but by referring back to June’s tweet I’d marked as a favorite, I was able to quickly write a similar one liner to locate what I was looking for:
Get-ChildItem -Path 'C:\Scripts\*.ps1' -Recurse | Select-String -Pattern "1.." -SimpleMatch | Select-Object -Property Path -Unique
Although I marked June’s tweet as a favorite on twitter, over time that favorite will become more difficult to locate which is why I’m blogging about it. My blog site is indexed so I’ll be able to quickly find this information the next time I need it.