Automate your VMTN search

Recently I had the pleasure of doing a guest post, called Finding your way in the PowerCLI Community, on the PowerCLI blog. The subject of the post was how to find community threads, that might hold an answer to your question.

Now this wouldn’t be a PowerShell/PowerCLI blog, if I didn’t try to automate the procedure. And with a serious amount of RegEx involved, I was able to create some working code. Here it is, my Find-VMTNPowerCLI function.

Warning: pure PowerShell, no PowerCLI content !

The script

Annotations

Line 63: The first thread in the PowerCLI Community dates from December 24th 2007. No reason to go further back in time 🙂

Line 77-149: An internal helper function. This is the real workhorse of the function, in here all the RegEx mgic takes place.

Line 80: The way Jive returns results for a community or a group is slightly different. Hence the Group switch, which will allow the function Get-VMTNSearch to act differently for the PowerShellers group.

Line 83-86: The ThreadData is returned in PST time (I suppose that is where the VMTN servers are located). These lines will calculate the time difference between the location where you run the script and PST time.

Line 88-93: The RegEx expressions that will be used in the function to extract the desired fields.

Line 96: The URL, which is passed from the calling function, contains the actual Search keywords. Here we download the results from the search and convert it to an XML list for further handling.

Line 97: The individual ‘items’ from the search result are retrieved and used to extract the data.

Line 103-108: The content of the reply post is interspersed with HTML code. The series of -Replace operators will convert and filter away the HTML tags.

Line 112: The function fetches the complete page for the thread. This required for extracting the properties that follow. The -Scope 1 parameter makes sure that the $page variable is available outside the calculated property code block.

Line 113-119: The RegEx string contains the bookmark for the specific reply we are looking at. That is why the script updates the RegEx string with the bookmark. The Reply field has a different layout depending if it comes from a Community or a Group.

Line 124,131: Some user names might contain blanks or other special characters, to avoid displaying the Javascript encoding for these special characters, the property value is decoded.

Line 136: The thread date is returned in PST time (see above). This converts the datetime value to your local time.

Line 151-155: All the VMTN Communities have a specific ID. This ID needs to be used in the search URL.

Line 156: The PowerShellers group has a specific type, different from the Community type.

Line 158: The basic Search page URL

Line 159: The search URL needs to have all special characters converted.

Line 160-164: The other parameters passed on the search URL

Line 164: On the Search page, the results are returned in batches of 10, 15 or 30. In the function we want all the results in one go, hence the maximum [int] value.

Line 171-186: The Get-VMTNSearch internal function is called for each of the selected communities.

Line 188-195: All the selected conditions are stored in a [string]

Line 196: The string with the conditions is converted in a code block

Line 197: The generated code block is used in the Where-clause to filter the results according to the passed parameters.

Sample usage

The function is quite simple to use. The Question parameter accepts the exact same search strings as you can enter on the Search page. See the VMTN Search Tips for the details.

A simple example that will look for the keyword ‘move-vmthin‘ in the PowerCLI Community.

The resulting CSV file looks like this

Note that in the Text column you can find the complete content of the reply. This can make it quite easy to copy code to your favorite PowerShell editor.

The next example will look for the text ‘baseline groups remediate-inventory‘ only in the Update Manager PowerCLI Community.

The result

With the search functionality, you could for example look for replies that contain functions. Searching for the words ‘function param‘ we would find quite a number of replies that contain code.

The resulting CSV file contains 167 rows. Perhaps a bit too much. So let’s limit the replies to a specific time period. We only look for replies after September 1st 2011.

Much better, now we find 23 replies, with recent code.

A word of warning

I’m pretty sure there are some threads around that will break the function. With so many threads and replies in these very active PowerCLI related communities and groups, there are bound to be some that I didn’t encounter during my tests and that will break the function.

Should you encounter something like that, feel free to post the parameters in the comments for this post and I will try to fix the function.

Enjoy !

2 Comments

    Search VMTN with REST API - LucD notes

    […] API are (nearly) everywhere! VMware’s VMTN website is no exception. I already did a post on Automate Your VMTN Search, but that was entirely based on constructing URI and interpreting the returned webpages. For the […]

    Ammesiah

    I really like the warning :p
    Great job btw, like always ^^

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*

Buy the Book

Top Viewed Content