How to close IE sessions opened by Invoke-WebReque

2019-05-14 08:54发布

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?

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

1条回答
劫难
2楼-- · 2019-05-14 09:33

To forcefully close all IE sessions use:

get-process iexplore | stop-process

To more gracefully close IE sessions use:

Get-Process iexplore | ForEach-Object { $_.CloseMainWindow() }

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.

查看更多
登录 后发表回答