64

So I decided to start using PowerShell rather than Command Prompt. And I want to run curl. Very different output then discover that curl is an alias to Invoke-WebRequest in PowerShell.

Using PowerShell curl in the same way as real curl, I only get part of the content displayed.

I have seen that I can put the output of PowerShell curl into a variable and then use $variable.Content to display all of the content but that seems extra work over real curl.

Is there an option to show all of the content directly? I can't see one in the help.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
John
  • 1,593
  • 3
  • 17
  • 28

3 Answers3

101

Unlike the curl command line utility Invoke-WebRequest returns an object with various properties of which the content of the requested document is just one. You can get the content in a single statement by expanding the property like this:

Invoke-WebRequest 'http://www.example.org/' | Select-Object -Expand Content

or by getting the property value via dot-notation like this:

(Invoke-WebRequest 'http://www.example.org/').Content

Alternatively you could use the Windows port of curl:

& curl.exe 'http://www.example.org/'

Call the program with its extension to distinguish it from the alias curl for Invoke-WebRequest.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
  • 1
    `Invoke-WebRequest 'http://www.example.org/' | Select-Object -Expand RawContent` if you want to see the response headers – tolache Oct 20 '20 at 10:04
6

Well, if you are bothered with extra typing this is the shortest way to achieve that (well, at least I can think of):

(iwr google.tt).content
4c74356b41
  • 69,186
  • 6
  • 100
  • 141
3

Something like this?

$res=Invoke-WebRequest "https://www.google.fr/" 


#to view html of body
$res.ParsedHtml.body.innerHTML

#to view text of body
$res.ParsedHtml.body.innerText
g t
  • 7,287
  • 7
  • 50
  • 85
Esperento57
  • 16,521
  • 3
  • 39
  • 45