powershell - Invoke-WebRequest 未被识别为 cmdlet Windows 7 Powershell 的名称

标签 powershell windows-7-x64 invoke-webrequest

如何在 Windows 7 PowerShell 上使用此脚本?

$IE = new-object -com internetexplorer.application
$go = (Invoke-WebRequest –Uri ‘c:\link.html’).Links.href  
$IE.navigate($go)
$IE.visible=$true
start-sleep 5
$word=$go = (Invoke-WebRequest –Uri ‘c:\word.html’).Links.href 
$Link = $IE.Document.getElementsByTagName("span") | ? {$_.InnerHTML -eq "$word"}
$word2=$go = (Invoke-WebRequest –Uri ‘c:\word2.html’).Links.href 
$ie.Document.getElementsByTagName("$word2").item(0).click()

运行此脚本后,我收到此错误:

The term 'Invoke-WebRequest' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:7 char:29
+     $go = (Invoke-WebRequest <<<<  –Uri ‘http://lapfix.ir/link.html’).Links.href  
    + CategoryInfo          : ObjectNotFound: (Invoke-WebRequest:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

The term 'Invoke-WebRequest' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify t
hat the path is correct and try again.
At line:12 char:31
+ $word=$go = (Invoke-WebRequest <<<<  –Uri ‘http://lapfix.ir/word.html’).Links.href 
    + CategoryInfo          : ObjectNotFound: (Invoke-WebRequest:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Cannot find an overload for "getElementsByTagName" and the argument count: "1".
At line:13 char:42
+ $Link = $IE.Document.getElementsByTagName <<<< ("span") | ? {$_.InnerHTML -eq "$word"}
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest

You cannot call a method on a null-valued expression.
At line:14 char:12
+ $Link.click <<<< ()
    + CategoryInfo          : InvalidOperation: (click:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

我认为错误是不能在 Windows 7 上使用 Invoke-WebRequest。为什么会这样?

最佳答案

默认情况下,Windows 7 安装了 PowerShell 2.0 版。 Invoke-WebRequest cmdlet 是在 PowerShell 3.0 版中引入的。

最简单的解决方案是将您的 PowerShell 版本升级到 3 或更高版本(我建议只安装最新版本:5.1)。您可以通过下载 Windows 管理框架来做到这一点:

https://www.microsoft.com/en-us/download/details.aspx?id=54616

关于powershell - Invoke-WebRequest 未被识别为 cmdlet Windows 7 Powershell 的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53035692/

相关文章:

forms - 如何使用 pwsh 中的新 param -form 登录网站

通过网络解锁 Windows session

powershell - 有没有办法为运行时模块或脚本 block 编写帮助文本?

powershell - 是否可以在 PowerShell 中的 bool[] 中包含 [Nullable[bool]]

svn - 在Windows 7计算机上安装哪个svn客户端?

JSON 因 UTF-8 起始字节 0xa0 无效而被拒绝,但编码似乎有效

powershell - Start-Process powershell 凭据不起作用,但在使用 cmd 时会起作用

iis-7.5 - 为什么即使 'enable32BitAppOnWin64' 设置为 False,我的站点仍会尝试加载 32 位 aspnet_filter.dll?

java - 无法安装Android开发工具包: Says Missing JDK

powershell - 使用 Invoke-WebRequest 时,如果使用 UseBasicParsing,为什么我只能连接到某些 URL?