Windows PowerShell命令未在批处理脚本中执行
我在批处理文件上写了以下命令,以通过PowerShell命令从远程URL获取我的计算机的公共IP:
@echo off
setlocal EnableDelayedExpansion
call :MyIP2
timeout /t 50
EXIT /B 0
:MyIP2
echo Obtaining my IP...
For /f %%A in ('powershell -NonI -NoP -C "(Invoke-Webrequest http://componentsearch.everscrape.com/scraper/ip).content"') Do echo %%A
EXIT /B 0
现在,当我尝试执行批处理文件(即使作为管理员运行)时,我得到了以下OUPTUT而不是公共IP我正在使用的计算机。
Obtaining my IP...
Invoke-Webrequest
Internet
At
+
+
+
+
d
我目前正在运行Windows Home,并安装了所有更新。请非常感谢任何帮助。
I have the following commands written on a batch file to obtain my computer's public IP from a remote URL via powershell command:
@echo off
setlocal EnableDelayedExpansion
call :MyIP2
timeout /t 50
EXIT /B 0
:MyIP2
echo Obtaining my IP...
For /f %%A in ('powershell -NonI -NoP -C "(Invoke-Webrequest http://componentsearch.everscrape.com/scraper/ip).content"') Do echo %%A
EXIT /B 0
Now when I try to execute the batch file (even run as administrator), I got the following ouptut instead of the public IP of the computer I'm using.
Obtaining my IP...
Invoke-Webrequest
Internet
At
+
+
+
+
d
I'm currently running Windows Home with all the updates installed. Please any help is greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
发布答案以确保对此有清晰度。
此错误具有明确的消息,实际上是两个。它向您显示了对IE的依赖性作为Windows上的解析器,更重要的是,它显示了此行中的修复程序:
仅添加
-UseBasicParsing
参数将直接解决该问题,而无需最初运行IE即可。此文档
Posting an answer to make sure there is clarity on this.
This error has a clear message, well two in fact. It shows you the dependancy on IE as a parser on windows and more importantly it shows you the fix in this line:
Simply adding the
-UseBasicParsing
parameter will therefore directly solve the issue without needing to run IE initially.This is also clearly stipulated in this documentation
尝试这样的尝试:
或
URL需要以双引号为单位,但要在批处理时逃脱它们,您需要使用三重双引号。
try like this:
or
the URL needs to be in double quotes but in order to escape them when called from batch you need to use triple double quotes.
似乎这个问题似乎发生在新鲜的窗户上。要解决,请启动Internet Explorer,然后选择推荐的设置。
It seems this issue seem to occur on fresh installed windows. To fix, launch the Internet Explorer and select Recommended Settings.