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:

[System.Diagnostics.Process]::GetCurrentProcess()

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

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: