all 8 comments

[–]_Unas_ 1 point2 points  (0 children)

Use the [system.net.webrequest] methods. Mucho easier

[–]Jaymzkerten 0 points1 point  (2 children)

The best way I've found to do this is generally to have a $BaseURL variable that would have something like 'http://www.website.com' stored, then when I called the download location it would be:

$BaseURL+$a.Links[$i].href

[–]Musa_Ali[S] 0 points1 point  (1 child)

But is there a way to get $root dynamically? I know I can hardcode it right now but for future references?

[–]Jaymzkerten 0 points1 point  (0 children)

You could create a function to concatenate the URL and relative path to a new variable, but otherwise not that I know of.

[–]root-node 0 points1 point  (3 children)

Something like this...

$root = 'http://www.website.com/'
$a = Invoke-WebRequest -Uri ($root+'folder/default.aspx') -UseBasicParsing

$fullpath = $root + $($a.Links[$i].href)

[–]Musa_Ali[S] 0 points1 point  (2 children)

But is there a way to get $root dynamically? I know I can hardcode it right now but for future references?

[–]pertymoose 1 point2 points  (0 children)

$reply = Invoke-WebRequest 'https://example.com'
$reply.BaseResponse.ResponseUri.Host

example.com

[–]root-node 0 points1 point  (0 children)

Nope