如何关闭由Invoke-WebRequest打开的IE会话 [英] How to close IE sessions opened by Invoke-WebRequest
问题描述
我在脚本中注意到 Invoke-WebRequest
正在启动Internet Explorer(大概是在解析DOM)。有没有办法在脚本结尾关闭这些IE会话以进行清理?
I am noticing in my script that Invoke-WebRequest
is launching Internet Explorer (presumably to parse the DOM). Is there a way to close down these IE sessions at the end of my script, for cleanup purposes?
红色突出显示的行是 iwr
,提示Internet Explorer打开。如果我向该$ AllRegs请求添加 -UseBasicParsing
,该脚本将在两行后失败,尝试捕获 $ LibraryID
The line highlighted in red is the iwr
which prompts Internet Explorer to open. If I add -UseBasicParsing
to that $AllRegs request, the script fails a couple lines later, trying to capture $LibraryID
推荐答案
要强制关闭所有IE会话,请使用:
To forcefully close all IE sessions use:
get-process iexplore | stop-process
要更正常地关闭IE会话,请使用:
To more gracefully close IE sessions use:
Get-Process iexplore | ForEach-Object { $_.CloseMainWindow() }
您也可以在ForEach调用后添加等待,但我使用同一行关闭Chrome浏览器&从来没有必要。
You can also add a wait after the ForEach call, but I use the same line for shutting Chrome down & it has never been necessary.
这篇关于如何关闭由Invoke-WebRequest打开的IE会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!