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:
1 2 | 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:
1 | (Invoke-WebRequest -Uri 'www.jaapbrasser.com').Links.Href |
To ensure that only the unique links are selected Select-Object -Unique can be used:
1 2 | (Invoke-WebRequest -Uri 'www.jaapbrasser.com').Links.Href | Select-Object -Unique |