Recently I published a PowerShell function that I use to display a random Git Tip of the Day. The function relies on my clone of the Git-Tips project on GitHub. I've been keeping tabs on this project and a question was posed about creating a command line utility to search the tip list. Now, this project is most likely aimed at developers, at least based on what I've seen in the list of questions and issues. But for PowerShell people, this is a pretty simple thing to pull together.
ManageEngine ADManager Plus - Download Free Trial
Exclusive offer on ADManager Plus for US and UK regions. Claim now!
I already have a local clone of the project which includes a json file. As in my Show-GitTip script, I know I can use ConvertFrom-Json to turn the json file into a objects. The object has a title property so it wouldn't be that difficult to use Where-Object to filter on a word. So I quickly put together a new function I call Find-GitTip.
Most of the function should be easy to follow. The only thing I changed was to explicitly turn each converted json object into a PSCustomObject. When I piped to ConvertFrom-Json PowerShell was giving my an object of type System.Object[] and Where-Object wasn't filtering on the title. I probably could have adjusted the Where-Object expression but opted for the current solution. By the way I discovered all of this by piping results to Get-Member. This is a tip I always recommend: if you aren't getting the results you expect, backup and pipe to Get-Member to see exactly what PowerShell is writing to the pipeline.
The function will search for any text in the tip title:
You can also use regular expressions.
My script file that defines the function also defines an alias which of course you can change.
I hope you'll let me know what you think. If you run into any problems, please post them on the Gist page for this script.
Enjoy!
I am wondering why you don’t grab the tips.json file from the web to ensure you have the latest copy
I wondered when someone would notice! Personally, I already have a local clone so it was easier, faster and works when I am on an airplane. But I have something lined up for this very task. Stay tuned.
Here’s the online version: http://bit.ly/28VPwds