I did not know you could do that with #Powershell

So I have a few scripts that run using the task scheduler, and recently I have noticed a shed load of cmd.exe and powershell.exe running, where the script for some reason has not completed. So a bit of googling and found some interesting stuff.

To get the current PID for the powershell session you are running:


Now the funky bit, get a list of all cmd.exe and powershell.exe that are running:

get-wmiobject win32_process|where{($_.name -eq “powershell.exe”) -OR ($_.name -eq “cmd.exe”)} | sort processid | select processid,processname,commandline | ft –wrap

Now the wicked bit here is the commandline value (wow you can see it in taskmanager too Winking smile) it shows you what the commandline is that was used to execute the cmd or powershell.

Now just need to work on a wrapper that will stop the process if it’s already running

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: