I tried to get the foreground Window and write it in a file. After a few tries, I've only got the task list. Now I discovered this Code, but it won't work for me:
Add-Type @"
using System;
using System.Runtime.InteropServices;
public class Tricks {
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
}
"@
$a = [tricks]::GetForegroundWindow()
get-process | ? { $_.mainwindowhandle -eq $a }
Thanks :)