# Import the required .NET assembly Add-Type -TypeDefinition @" using System; using System.Runtime.InteropServices; using System.Threading; using System.Windows.Forms; public class WindowSwitcher { [DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow(); [DllImport("user32.dll")] public static extern bool SetForegroundWindow(IntPtr hWnd); } public static class SendKeysHelper { public static void SendAltTab() { SendKeys.SendWait("%({TAB})"); Thread.Sleep(1000); // Wait for the switch to complete } } "@ # Function to switch to the next window function SwitchToNextWindow { $currentWindow = [WindowSwitcher]::GetForegroundWindow() $nextWindow = (Get-Process | Where-Object { $_.MainWindowHandle -ne [IntPtr]::Zero -and $_.MainWindowHandle -ne $currentWindow }).MainWindowHandle if ($nextWindow -ne [IntPtr]::Zero) { [WindowSwitcher]::SetForegroundWindow($nextWindow) } } # Loop to continuously switch between windows every 2 minutes while ($true) { SwitchToNextWindow [SendKeysHelper]::SendAltTab() Start-Sleep -Seconds 120 # Wait for 2 minutes before switching to the next window }