Set console Top-Most in PowerShell


So while there is much advise about how to set forms topmost, i couldnt find anything that makes my console run topmost.

So my question: How do I make my console run top-most during a script?


This requires some .NET interop, as detailed in this blog:

Scripts From TechEd 2012… Part 1 (Keeping PowerShell Window On Top)

I’ve copied the relevant code below in case the linked site disappears:


As described in the comments: If you’re from a batch file, PowerShell runs in a child process and doesn’t own the console window, so you’ll have to make changes:


Set console Top-Most in PowerShell by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply