Run Background Commands after Every Command

There was a time in the not so distant past, where I specifically remember wondering how I might be able to get something to happen, every time any command ran in my Windows PowerShell console. And, I don’t just mean commands. Any operation, or error, or fat fingered mess, followed by a press of the Enter key. We know that things happen in between commands. The list of commands in the current session history, and the $? variable, are updated as one command completes, and the console readies itself for the next instruction.

So how does one take an action, or make something occur, no matter what the user enters in the console host, or ISE? As almost as quick as I asked myself the question, I had a thought: the prompt function. That function runs when you open the console, and then every time the Enter key is pressed, whether or not something was actually typed.

Follow me, and find out how I took advantage of the prompt function:

About Tommy Maynard

IT Pro. Passionate for #PowerShell, #AWS (certified x2), & all things automation. I'm not done learning. Author in #PSConfBook. Writes at