Want to download web url content

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 abc.com/#/queues -Credential "guest" $WebClient = New-Object System.Net.WebClient $WebClient.DownloadFile('abc.com/#/queues/%2F/onp.document.dlq','C:\Users\ankitpar\test.txt')

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

Thanks
Ankit

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.

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.

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