PowerShell 2.0+
In PowerShell 2.0+, you can run the following code to download a website's HTML/XML to a file:
$webclient = new-object system.net.webclient;
$webclient.DownloadString('https://www.google.com/') | Set-Content -Path .\file.txt
You can reduce this to one line as:
(new-object system.net.webclient).DownloadString('https://www.google.com/') | Set-Content -Path .\file.txt
which can be run from the command line as:
powershell.exe -executionpolicy --command "(new-object system.net.webclient).DownloadString('https://www.google.com/') | Set-Content -Path .\file.txt"
PowerShell 3.0+
In PowerShell 3.0+, you can run the following code to download a website's HTML/XML to a file (as suggested by Squashman):
$R = Invoke-WebRequest -URI https://www.google.com/
$R.Content | Set-Content -Path .\file.txt
You can reduce this to one line as:
(Invoke-WebRequest -URI https://www.google.com/).Content | Set-Content -Path .\file.txt
which can be run from the command line as:
powershell.exe -executionpolicy --command "(Invoke-WebRequest -URI https://www.google.com/).Content | Set-Content -Path .\filer.txt"
In most cases, you'll also need to add code to handle line endings, which are often only \n
. Many Windows text editors (like Notepad), will not display those, so it would make sense to replace them with \r\n
.