The term 'Invoke-WebRequest' is not recoginzed as the name of a cmdlet

我只是一个虾纸丫 提交于 2019-12-04 22:19:48
Fenton

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

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()
Steve Radich-BitShop.com

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.

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.

Ionut Hulub

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!