Creating a GitHub Repository from PowerShell

I’ve been continuing to work with the GitHub API in PowerShell. Today I have a function you can use to create a new GitHub repository. Of course you will need to have a GitHub account and another piece of critical information, but after that it is quite easy to create new repositories. This makes it easier for you to automate provisioning new projects, which is something else I’m working on. But for now, let’s create some repos!

Continue reading “Creating a GitHub Repository from PowerShell”

PowerShell 6.0 Release Tools

As you should be aware, the next version of PowerShell is open source and cross-platform. You will be able to run PowerShell v6 on Windows, a Mac and select Linux distributions. All of the code is currently in alpha and hosted on the PowerShell GitHub repository. This is also where you can download new builds to install and test. I’ll admit I’m a little behind the curve and part of that is because I don’t often check if there is a new release. So I built a PowerShell module that will do that for me, and even download new installation packages. The best part, is that this should work cross-platform.

Continue reading “PowerShell 6.0 Release Tools”

Friday Fun: Holiday Shopping with PowerShell

Once again, the holiday shopping season is upon us. But perhaps PowerShell can make it a little easier or at least a bit more fun. I’m sure many of you have shopped at Perhaps you plan to do so again this year for friends, family or even yourself. So why not let PowerShell make this a bit easier.

NewEgg is savvy enough to publish RSS feeds for a number of their sales categories. You can find a master list at  Let’s take their Deal of the Day feed.

Using Invoke-RestMethod, it is very easy to retrieve items.

But it is still a bit of a jumble, so let’s get a bit more selective.

I also created a new property called Published which takes the original PubDate and treats it as a date which makes the data easier to sort or filter.

Here’s a sample of what I retrieved.

A NewEgg Deal of Day itemA NewEgg Deal of Day item (Image Credit: Jeff Hicks)

With this data, I can use Out-Gridview as an object-picker.

Links in Out-GridviewLinks in Out-Gridview (Image Credit: Jeff Hicks)

I can select multiple entries, click OK and each link should open up in my browser.

The online dealThe online deal (Image Credit: Jeff Hicks)

But let’s make things a bit more interesting. The Title property includes the price and description. I have no idea what these links look like in other parts of the world so you may have to adjust the following examples.

First, I’m going to define a regular expression pattern to use named captures to get the currency, in my case $, the price and the item description.

I’m going to re-download the data skipping any entry that doesn’t have what looks like a price in the title field.

My goal is to use Out-Gridview again with separate properties for the currency and price. I need the price to be numeric so that I can sort on it. I next get the currency symbol using the regex expression.

Then I can process the rest of the RSS data, using the regex object to parse out the price and description.

If you notice, I used the Currency value as a property name. Now when I use Out-Gridview I have a more flexible display.

Reformatted DealsReformatted Deals (Image Credit: Jeff Hicks)

If I’m shopping for a new laptop, I can select multiple entries, click OK and review them in my browser.

Viewing my choicesViewing my choices (Image Credit: Jeff Hicks)

I can repeat the process by changing the RSS feed, say to their Shell Shocker

If I repeat the previous steps, this will fail, which brings up something to keep in mind with regular expressions: know your data. You have to know what you are processing and that it follows a predictable pattern. At least if you want to keep your regular expression patterns relatively simple. The problem here is that there is only a single item. So my code to get the currency figure fails, because I don’t have an array. In this situation I could do this:

Although it might make more sense to come up with code that I can re-use.

But from here the code is the same.

Shell Shocker itemShell Shocker item (Image Credit: Jeff Hicks)

That might be something I want to look into, although sometimes the RSS feeds are bit behind the site. Sadly, in this case, the link works, but the product is something else. But you get the idea.

Enjoy your holiday weekend and be careful out there!

Getting the Weather Where On Earth

Yesterday I posted a popular article about using Invoke-WebRequest to get weather conditions. That function used the Yahoo web site but really only worked for US cities. So I also cleaned up and revised another set of advanced PowerShell functions (required PowerShell 3) that can retrieve weather information for probably any location on Earth. The first piece of information you need is your WOEID, or “Where On Earth ID”. Here is a function to do just that.

To use the function you specify some sort of search criteria such as a postal code or city name.

I saved my WOEID as a variable in my PowerShell profile. This function also uses Invoke-RestMethod. I included a parameter to write an XML document to the pipeline instead in case you want to modify the function and need some help discovering the data. The second function, Get-Weather, uses the WOIED to get the current weather conditions. It too uses Invoke-RestMethod to retrieve the data. The resulting XML document is then parsed out using Select-XML to build an output object.

You can also change the temperature units.

I wrote these as two separate functions, I suppose I could have nested Get-Woeid inside Get-Weather, although the better option is probably to build a module. I’ll leave that for you. The functions are designed to take advantage of pipeline binding so that you can pipe Get-Woeid to Get-Weather.

You can even get weather for multiple locations.

This weather source includes a lot of information so I created a parameter to control how much detail to display. What you see above is basic information. But there is ‘extended’.

Or you can see everything with a detail setting of ‘all’.

Notice that url at the end? As the cherry on top, you can open the weather forecast in a browser using the Online parameter.

There you have it. No matter where you are you can check the weather. Or look out a window.


Baby, It’s Cold Outside

I don’t know about your neck of the woods, but it is downright Arctic here. So I thought I’d polish up my PowerShell function to get weather data.

This function uses the Yahoo weather RSS feed for US locations. The function uses the Invoke-RestMethod to get an entry for a given zip code. I set my zip code as the default and suggest you do the same. You will need to modify the default value in the code above. Invoke-RestMethod gives me an XML document so it isn’t too difficult to pull out the values I want and construct a custom object. I even use some regular expression named captures to break out the location and time. So hopefully there are some good learning examples here.

Anyway, quite frigid here, and this is already 5 degrees warmer than when I got up.


Hope you are staying warm.