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

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.
来源:https://stackoverflow.com/questions/37028778/how-to-close-ie-sessions-opened-by-invoke-webrequest