Monday, September 29, 2014

PowerShell script - Refresh Internet Explorer (IE) at intervals

Powershell script to refresh Internet Explorer (IE) at frequent intervals. This script is handy for Enterprise applications or sites that timeout or automatically log off the user after specific intervals of time.

In my case it was my Citrix Storefront application that timed out every 5 mins on non-activity. I used to enter my Network password and Citrix image password atleast 30-40 times in a day. I decided to write a script that would refresh my IE browser window at every 3 minute interval.

You can change the browser URL and Refresh time interval values highlighted in yellow below as per your requirements. Copy and Paste the below script in a PowerShell editor, save the file with .ps1 extension.

$ie = New-Object -com internetexplorer.application;
$ie.Navigate("https://www.mycitrixstorefront.com/default.aspx")
$ie.Visible = $true

$i = 0;

# Wait for the page to load
while ($i -ge 0)
{
    Write-Host 'IE Refresh count: ' + $i
    Start-Sleep -Seconds 180
    $i = $i+1;
    $ie.Refresh()
}

You can then create a .BAT file and reference the .ps1 script. The batch could then be scheduled in the Windows Task scheduler or executed manually to refresh your IE browser at frequent intervals

cd /d %~dp0
powershell -noexit -file ".\RefreshIE.ps1"%CD%"
pause

8 comments:

  1. Thanks for this lil' script, does what it needs to do. Clean and easy.

    ReplyDelete
  2. I know this is an old post, but I do thank you for the script.

    after executing the script, IE opens to the desired page, but I am having an issue though. I am seeing errors where powershell is displaying a Method invocation error and states that $ie.Refresh() is not a function.

    Any thoughts

    ReplyDelete
  3. I suspect you could be using Powershell version v2.0? I have tested this script on Powershell v 4.0

    ReplyDelete
  4. Awesome script! Can I make two requests?
    1. Allow script to work with other browsers (Chrome, Firefox, etc...)
    2. Refresh a specific, already opened tab instead of opening an new instance of the browser.

    I've been trying to modify your script to do this with no luck.

    ReplyDelete
  5. If I could ask to modify one thing, Can you make IE maximized when opened? It opens small and I have to maximize it every time the file is ran.

    ReplyDelete
  6. Hi,

    Where to save the file ?
    What do we need to use the script ? Only IE or other programs ?

    I want to use it on a user acces PC, not Admin, so i can't do so many things.

    Tk's

    ReplyDelete
  7. You can save the .ps1 file either on your desktop or any drive. With your current permission set, you should be able to open this script in Powershell

    ReplyDelete
  8. Today's reality PCs turn into the piece of our every day life and our put away information is sheltered and secure in it yet a portion of the issues can without much of a stretch constrain you to reconsider in light of the fact that if PC is dealing with your critical information then it likewise require some of insurance layer around it to ensure the information itself since it can undoubtedly seized from various infections on URLs, sites and so on. https://how-to-remove.org/malware/adware-removal/search-ydserp-com-removal/

    ReplyDelete