How can I detect whether or not I am in powershell from a command line?
cmd, command-line, powershell
Solution
One way, it to see what your process name is, and then check its attributes:
title=test
tasklist /v /fo csv | findstr /i "test"
As long as you use a unique name in place of Test, there should be little room for error.
You will get back something like:
"cmd.exe","15144","Console","1","3,284 K","Running","GNCID6101\Athomsfere","0:00:00","test"
When I ran the above code from a bat file, my output was:
"powershell.exe","7396","Console","1","50,972 K","Running","GNCID6101\Athomsfere","0:00:00","
Problem
I am creating a standard windows BAT/CMD file and I want to make an IF statement to check whether or not this CMD file is run from PowerShell. How can I do that? Edit: My underlying problem was that `test.cmd "A=B"` results in `%1==A=B` when run from CMD but `%1==A` and `%2==B` when run from PowerShell. The script itself is actually run as an old Windows Command line script in both cases, so checking for Get-ChildItem will always yield an error.