<# .SYNOPSIS Refreshes the active Chrome tab at a fixed interval (for unattended display screens). .PARAMETER IntervalMinutes Minutes between refreshes. Default: 10. .EXAMPLE powershell.exe -ExecutionPolicy Bypass -File .\Refresh-Chrome.ps1 -IntervalMinutes 5 #> param( [int]$IntervalMinutes = 5 ) Add-Type -AssemblyName System.Windows.Forms # Win32 helpers to restore and focus the Chrome window Add-Type @" using System; using System.Runtime.InteropServices; public class WinApi { [DllImport("user32.dll")] public static extern bool SetForegroundWindow(IntPtr hWnd); [DllImport("user32.dll")] public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow); [DllImport("user32.dll")] public static extern bool IsIconic(IntPtr hWnd); } "@ while ($true) { $chrome = Get-Process chrome -ErrorAction SilentlyContinue | Where-Object { $_.MainWindowHandle -ne 0 } | Select-Object -First 1 if ($chrome) { $handle = $chrome.MainWindowHandle # Restore the window if it was minimised (9 = SW_RESTORE) if ([WinApi]::IsIconic($handle)) { [WinApi]::ShowWindowAsync($handle, 9) | Out-Null } [WinApi]::SetForegroundWindow($handle) | Out-Null Start-Sleep -Milliseconds 500 # Send F5 to reload the active tab [System.Windows.Forms.SendKeys]::SendWait("{F5}") Write-Output "$(Get-Date -Format 's') Chrome refreshed" } else { Write-Output "$(Get-Date -Format 's') Chrome window not found, will retry" } Start-Sleep -Seconds ($IntervalMinutes * 60) }