Author Posts

May 22, 2018 at 10:26 am

Hi All,

I have one url and I want to download the all web url content and copy it to some text file but unable to do so. That URL have username and password as well so please guide how to do this. Do I need to pass credentials also in script. If yes, then how. Any insight would be appreciated.

Till now code is –

Invoke-WebRequest -Uri -Credential "guest"
$WebClient = New-Object System.Net.WebClient

but on executed it's not giving the desired result. It's not copying the web page.


May 30, 2018 at 2:57 am

If the website prompts, on the website itself, for a username and password, then you're basically going to have to write code that will pretend to be a user submitting that information. It's not terribly easy, although the examples in the help file for Invoke-WebRequest include a Facebook example.

If the website is using a pop-up dialog for username/password, then yes, you can submit that as a -Credential parameter.

If the website is accepting a user name and password as URL query string parameters, then you'd just use that as the URL for Invoke-WebRequest.

May 30, 2018 at 2:59 am

Also, I'll note that you're doing two things. The Invoke-WebRequest has nothing to do with the $WebClient. You should pick one or the other; if you're using WebClient, then you're really outside PowerShell and using the .NET Framework directly. A developer website like StackOverflow might be a better place to ask for help on the .NET Framework. Invoke-WebRequest is somewhat more limited than WebClient, although Invoke-WebRequest does use WebClient under the hood.

May 31, 2018 at 2:25 pm

Thanks for reply and advise. I will follow the same. Thank you