Major error in WIN 7 64 enterprise

from CMD:

powershell -nologo -noprofile -command "get-process | sort-object Id | cat "

Causes major issues with the operating system... WHY?

Who is Participating?
simon3270Connect With a Mentor Commented:
The first two commands work as expected - get-process returns a process list table, then sort-object sorts it on the specified column (Id).  The problem is the "cat".

"cat" in powershell is an alias for "get-object", which gets an object specified as an argument and writes it to the output.  So, for example,
    cat my_file.txt
will display the contents of my_file.txt.  So far, it is like the UNIX "cat" command.  Problems start when you specify just
as a command (as you do in your pipeline.  It seems just to produce a seemingly neverending list of error messages, or repeatedly outputs its  input.

    powershell -nologo -noprofile -command "get-process | sort-object Id"
will list processes as you wanted.  The "cat" is not required.
KonfigurationKingAuthor Commented:
there is also a beeping noise coming from my computer.
Well, I don't have an answer as to why (it's an interesting question), but I do have to ask why you would want to run that command?  Or was it just a mistake you ran across while writing a script?
WEBINAR: GDPR Implemented - Tips & Lessons Learned

Join the WatchGuard team on Thursday, March 29th as we recount some valuable lessons learned in weighing the needs of a business against the new regulatory environment, look ahead at the two months left before implementation, and help you understand the steps you can take today!

KonfigurationKingAuthor Commented:
I am trying to learn how to write scripts ... I am curretnly reading windows powershell 2.0 microsoft press
The problem is that you are trying to display binary data on the screen - this will produce the characters you see, and the beeping (probably when it tries to display a byte with the value 7).

Try the individual commands interactively in powershell, to see what the output looks like.  Only when you are happy that you are displaying the right text should you try to script it.
footechConnect With a Mentor Commented:
I thought about this a bit last night.  Get-Content (cat) retrieves the contents of a file.  If you open an executable file with Notepad (or some other text viewer) you'll see something similar.  The reason your command produces output (even if it's strange-looking) and doesn't just error out is because Get-Process outputs objects with a scriptproperty called "path", and Get-Content has a path parameter which accepts pipeline input.  So basically what you're doing is telling Get-Content to read the content of every file in the process list.  You'll see the same behavior if you just run
gc c:\pathTo\someExecutable.exe
As to the beeping, simon3270's explanation seems correct.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.