29

I've got problem with executing Invoke-WebRequest cmdlet. I read that ~100% case of that scenario is PS version lower than 3, but it's not my case:

Name                           Value
----                           -----
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
CLRVersion                     4.0.30319.34011
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.10208.0
PSVersion                      5.0.10208.0
SerializationVersion           1.1.0.1

I can add that I'm using Windows 10 IoT Core version of OS. In fact my main purpose is execution of simple web request, but I am interested why this cmdlet is not working, especially if more of them won't be ;/ I suppose it can be some windows feature like switch to turn on, but its just my guess.

Update

As far as I compared available cmdlets for certain modules, and preloaded assemblies between my regular system and an IoT version, it looks like the latter version is cut somehow, but I still didn't see any docs for that.

zett42
  • 25,437
  • 3
  • 35
  • 72
Dawid Komorowski
  • 538
  • 1
  • 6
  • 15
  • Just curious, is `Invoke-RestMethod` missing too? – briantist Aug 31 '15 at 16:42
  • @briantist What are you thinking? – Matt Aug 31 '15 at 17:48
  • I found another post about a missing commandlet: measure-command. If that's missing for you as well, maybe IoT is stripped down without documentation. – William Nelson Aug 31 '15 at 17:55
  • Those are all part of the module `Microsoft.PowerShell.Utility`. Wonder if that is missing then or incomplete. Do you see that in the list when you try `Get-Module`? Although `Get-Host` is in there where the info from the OP would have come from. Wonder if it is present but limited – Matt Aug 31 '15 at 17:57
  • @Matt yeah I noticed the same thing, that it's in that module but it seems really unlikely that the entire module would be missing. But `Invoke-RestMethod` uses the same underlying .Net object to do its dirty work, so I was wondering if it might too be missing. – briantist Aug 31 '15 at 18:09
  • Answering your questions: 1. Invoke-RestMethod is missing too 2. Output of Get-Module says that Microsoft.PowerShell.Utility in version 3.1.0.0 is loaded FYI Get-Command Invoke-WebRequest | fl * ends up with same error – Dawid Komorowski Sep 01 '15 at 06:51
  • Does this work: `New-Object System.Net.WebClient`? – briantist Sep 02 '15 at 23:40
  • I tried direct access to .Net commponents but it also fails. What is more app written in C# targeting .Net is limitted in the same manner. As far as I searched, IoT has very limitted API which is mainly UWP. – Dawid Komorowski Sep 03 '15 at 17:51
  • @DawidKomorowski yeah it seems obvious at this point that that will be the case, but I'd sure love to see documentation on what is and isn't available. That seems awfully important! – briantist Sep 04 '15 at 21:48

6 Answers6

13

I had this issue on a Windows Server 2008 R2 server, because it was running PowerShell v2. Upgrading to v4 fixed the issue.

Windows Management Framework 4.0 (includes PowerShell 4.0)

As of v5, Invoke-WebRequest is still documented.

Check your version with:

$PSVersionTable.PSVersion
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Fenton
  • 241,084
  • 71
  • 387
  • 401
7

Trying to create the request in the same way I would do it for PS version 2 (using .net library instead of cmdlet) doesn't work either...

$request = [System.Net.WebRequest]::Create("https://google.com")
$request.Method = "GET"
[System.Net.WebResponse]$response = $request.GetResponse()
Roberto
  • 567
  • 1
  • 3
  • 10
3

This appears to be removed in PowerShell Core.

I am searching for why this doesn't work on Docker for Windows running on Nano Server for Windows 2016 and your findings match mine.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
2

Though the PowerShell version and everything else was good at my end, I was unable to download the code from the desired repo. So, I've executed the following command first to satisfy the TLS version, and then I have executed my desired command to download the latest version of the githubActions runner.

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest -Uri 
https://github.com/actions/runner/releases/download/v2.165.2/actions-runner
-win-x64-2.165.2.zip -OutFile actions-runner-win-x64-2.165.2.zip
Iqra.
  • 685
  • 1
  • 7
  • 18
0

Invoke-WebRequest has been stripped from PowerShell 5.

Here's an implementation of a function called Invoke-FastWebRequest that works just like the old Invoke-WebRequest in PowerShell 5: https://github.com/cloudbase/unattended-setup-scripts/blob/master/FastWebRequest.psm1

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ionut Hulub
  • 6,180
  • 5
  • 26
  • 55
  • What do you mean by *"Invoke-WebRequest has been stripped from PowerShell 5"*? It worked fine in PowerShell 5.1.16299.785 when I tried it (Windows 10). [The documentation](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-webrequest) has *"Beginning with PowerShell 6.0.0 Invoke-WebRequest supports basic parsing only."*. – Peter Mortensen Dec 20 '18 at 10:11
  • Removed from [PowerShell Core](https://en.wikipedia.org/wiki/PowerShell#PowerShell_Core_6.0) (but that seems to start at version 6)? – Peter Mortensen Dec 20 '18 at 10:17
  • @PeterMortensen Could you please shortly explain where exactly the wiki reference you gave states that Invoke-WebRequest has been removed from PowerShell Core? I could not find such a statement there. – Binarus Mar 14 '19 at 08:10
-1

Using -UseBasicParsing option in the command works. The following is part of the command's documentation

-UseBasicParsing

Indicates that the cmdlet uses the response object for HTML content without Document Object Model (DOM) parsing.

This parameter is required when Internet Explorer is not installed on the computers, such as on a Server Core installation of a Windows Server operating system.

Community
  • 1
  • 1
Geo
  • 17
  • 1