Tag Archives: Invoke-Webrequest

QuickTip: Select all links using Invoke-WebRequest

Today I was looking for a way to discover all links on my blog. Invoke-WebRequest returns a number of interesting properties, which can be listed by piping the output into the Get-Member cmdlet:

Invoke-WebRequest -Uri 'www.jaapbrasser.com' |
Get-Member -MemberType Property

The output from the previous command shows that there is a property named ‘Links’, we will use this property to retrieve all the urls from a site. For example by executing the following code:

(Invoke-WebRequest -Uri 'www.jaapbrasser.com').Links.Href

To ensure that only the unique links are selected Select-Object -Unique can be used:

(Invoke-WebRequest -Uri 'www.jaapbrasser.com').Links.Href |
Select-Object -Unique



Geolocate an IP Address from PowerShell

PowerShell.com recently published a tip, Identifying Origin of IP Address, that allows you to get the country of an IP Address. Seeing how this was built I decide to write a similar function that gathers a bit more information. The function provides information about the IP,Country,City and actual Latitude and Longtitude of an IP Address as provided by http://freegeoip.net.

Function Get-GeoIP {
param (
    ([xml](Invoke-WebRequest "http://freegeoip.net/xml/$IP").Content).Response

The function takes an IP address as input and uses this to gather the results in XML-format from the freegeoip.net website. This output is then presented to PowerShell as an Xml element. The output can also be filtered using the Select-Object Cmdlet.


Quantum Random Number Generator, in PowerShell!

Recently I came across an article about a random number generator based on quantum effects in a vacuum. Scientists at The Australian National University have created the fastest random number generator based on this concept.

Sub-atomic particles appearing and disappearing measured by extremely sensitive light sensors are generating these random numbers. According to Quantum Theory these events are completely random and connect be predicted.

Because I thought the concept was quite interesting I decided to write a small PowerShell script, for PowerShell version 3. Using the new Invoke-Webrequest Cmdlet. The script grabs the content from the dedicated website and finds the block of 1024 hexadecimal characters.

Based on the parameters supplied to the script it can return either a hexadecimal number of 1 to 15 characters or a converted to a decimel integer. As a third option the script can also be leveraged to generate a seed to be used with the Get-Random Cmdlet, because a Quantum Seed is just so much better.

I have uploaded the script to the Microsoft Technet Gallery, you can check it out here:

Quantum Random Number Generator, in PowerShell

By all means check out the ANU Website as well, there are some guessing games as well, so you can try to beat the random generator.