Tag Archives: Scripting

Friday Fun: Get PowerShell User Groups

The other day Don Jones tweeted about find a PowerShell user group. In case you didn’t know, just about every user group associated with PowerShell can be found online at http://powershellgroup.org. This is a terrific resource for finding a user group near you. Of course, Twitter being what it is someone joked about the lack of a Get-PSUserGroup cmdlet. So, taking the joke as a challenge I built on. Don also was going to build something but I haven’t seen what he came up with. I suspect it will be similar to mine.

Because we there is a web site, we can scrape it with Invoke-WebRequest.

Instead of trying to parse the document object model (DOM), the resulting object has a property called AllElements which is exactly what the name implies. I had to look at the source HTML on the page to identify the elements I needed to reference. Since it seemed I could get what I want via an HTML class, I grouped the elements by class and turned it into a hashtable.

I opted for a hashtable to make it easier to get all the elements for a given class. For example, I knew the ‘views-field views-field-title’ class would give me the name of each group.

Likewise I knew the ‘views-field views-field-description’ class would provide a description.

Knowing what each object looked like, you could also pipe to Get-Member to discover property names, made it easy to extract the relevant information.

Once I had the core concepts down, I built an advanced function around them called Get-PSUserGroup.

The command doesn’t take any parameters and simply returns high level information about each group.

The pipelined object includes a link to the group’s page which means you could try something like this:

All of the groups are sent to Out-GridView.

Select one or more groups and each link should open in your browser. Now you have no excuse for not finding a PowerShell User Group. And if here isn’t one near you, start it!

I have some other interesting things on this topic, but I’ll save those for another day. Enjoy!!

PSBlogWeek Ebook and PDF Available

coverWe really appreciate the interest in our PowerShell Blog Week experiment. It was a lot of fun and it seems many of you got something useful out of it as well. I wouldn’t be too surprised if you don’t see another event later this year, most likely with even more contributors.

In the mean time, we thought you might like to have all of the #PSBlogWeek articles in one handy document. The original articles and links will remain in place, but this might come in handy for offline reading. You can download a PDF version of the file from here (right-click to save and download).

We’ve also produced the file in a few ebook reader formats which you are also welcome to download.

PSBlogweekApril2015-mobi

PSBlogWeekApril2015-azw3

PSBlogWeekApril2015-epub

Again, thanks for your interest and support. Enjoy!

Friday Fun: What’s My IP

Today’s Friday Fun is a “quick and dirty” solution to the question, “What is my public IP address?” There are plenty of web sites and services you can visit that will display that piece of information. Naturally I want an easy way to get this in PowerShell. Recently I came across a reference to a web site that simply displays your IP address. To see for yourself go to http://icanhazip.com/.

Pretty cool.

This means I can use PowerShell.
getmyip

The content property is all I need so here’s a one-liner.

Of course that’s a lot to type so I put together a simple function.

Now I can easily get my public IP.
getmyip2

Nothing fancy, just getting the job done. Enjoy.