Search code examples
windowspowershellinternet-explorerhidden

Viewing hidden Powershell/IE windows


I have a Powershell script that runs in the background and part of the script will use IE that is hidden. Sometimes this script gets hung up and I'd like to view the IE and Powershell windows to see where its stuck. I can't find a way to do this.

Sometimes Windows will give me a message if a script is running that a process is running and asks if I would like to view it and then I am able to view the windows then but I can't figure out away to do that without getting that message first.

I need to figure out where this script is getting stuck at. If I run it manually it works fine and works fine most times but every so often it gets stuck in the same place.

It's a Windows 10 machine that it's running on.


Solution

  • Open a powershell window and type in these commands to connect to your running internet explorer:

    $windows = (New-Object -Com "Shell.Application").Windows()
    $ie = $windows | Where-Object {$_.Name -eq "Internet Explorer"}
    $ie.Visible = $true
    

    That should connect you to the running IE instance and make the window visible again. If that doesn't work, I would check out what objects are in the $windows variable to see if it is even detecting your IE. If it doesn't detect it, you might need to make sure it is running with Administrator rights.

    After finding that the powershell script is starting the IE object in the remote session, I would instead implement a scheduled task and trigger that task remotely so that it will run in session 1 instead of session 0. More info on this issue with various other applications: http://psappdeploytoolkit.com/forums/topic/session-0-ui/

    https://github.com/PowerShell/Win32-OpenSSH/issues/998

    https://serverfault.com/questions/690852/use-powershell-to-start-a-gui-program-on-a-remote-machine