Set console Top-Most in PowerShell

Question:

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?

Answer:

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:

Edit:

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:

Source:

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

Leave a Reply