I am using the following code to start an IE process and navigate to a website.
$process = Start-Process "C:\Program Files (x86)\Internet Explorer\iexplore.exe" http://www.nu.nl -PassThru
Then I want to close this process so I use
This works beautifully ONLY when one Internet Explorer window is open. If there is already an Internet Explorer window open it will throw the following error
Exception calling "Kill" with "0" argument(s): "Cannot process request because the process has exited." At line:2 char:1 + $process.Kill() + ~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) , MethodInvocationException + FullyQualifiedErrorId : InvalidOperationException
How can I close only the Internet Explorer window that was opened from the Powershell session?