News for hackers. Stuff that matters.
Re:Microsoft Replaces Command Prompt with PowerShell in Late... by mauvehaus on Friday November 18, 2016 @08:39AM (#12986621)
That's nice. Can you pipe binary data without powershell corrupting it, or is that now a feature?

https://brianreiter.org/2010/01/29/powershells-object-pipeli...

Re:Microsoft Replaces Command Prompt with PowerShell in Late... by pjc50 on Friday November 18, 2016 @09:47AM (#12987060)
It's amazing, isn't it. They went to the effort of building a typed shell but didn't realise there are multiple different types of string.

I bet it still truncates output of the ">" operator to the console width, too.

Re:Microsoft Replaces Command Prompt with PowerShell in Late... by jodrellblank on Friday November 18, 2016 @12:43PM (#12988497)

    'troll' * 1000 > out.txt
Open in NotePad++, no weird newlines in the wrong place, content not truncated.

Were you using |format-table and |format-list (ft, fl) to explicitly format the text for console viewing, then redirecting that to a file?

Re:Microsoft Replaces Command Prompt with PowerShell in Late... by pjc50 on Friday November 18, 2016 @01:54PM (#12989135)
Took a while to reproduce the actual case, and it's Select-String that's at fault. And it must be in "powershell" not "powershell ISE".

  'troll' * 1000 > troll.txt
.. works fine as you say

  Select-String -Path .\troll.txt -Pattern "t" > t.txt
.. wraps the output at the console width. Which means you can't use it as a grep replacement.
Re:Microsoft Replaces Command Prompt with PowerShell in Late... by jodrellblank on Friday November 18, 2016 @02:27PM (#12989397)
You can't use it as grep in bash, because it isn't that. It outputs [MatchInfo] objects, not text, and Out-File (>) formats complex objects for console viewing (for ??? reasons), which is one reason > isn't a great PS habit.

    Select-String -Path .\troll.txt -Pattern "t" | Set-Content t.txt

    or

    sls 't' .\troll.txt | sc t.txt
Re:Microsoft Replaces Command Prompt with PowerShell in Late... by new_hackers on Friday November 18, 2016 @10:37AM (#12987433)
this ^^^

This is the main reason I still use cmd.exe

Re:Microsoft Replaces Command Prompt with PowerShell in Late... by gfody on Friday November 18, 2016 @11:09AM (#12987705)
Related, running something like decrypt hugefile.dat | encode outfile.dat will usually result in powershell using up all your system ram and crashing.
Re:Microsoft Replaces Command Prompt with PowerShell in Late... by brazzledazzle on Friday November 18, 2016 @11:40AM (#12988002)
On a somewhat related note, one of PowerShell's biggest weaknesses is memory utilization. And since they make it so simple to pass around hefty object collections it tends to bite you in the ass early on. Particularly when you're using cmdlets. When doing real scripting that actually needs to be run as a job I am surprised when I can get away with cmdlets and don't need to manage .net APIs/objects directly. Especially third party cmdlets.

One performance tip I picked up early on: If you're passing around large object sets you need to operate on try to keep them in a pipeline. Populating a variable and interacting with it is arguably more readable and maintainable, especially for junior people, but it has a heavy cost in terms of memory.

That said every version of posh is better than the last so I may be wrong or overestimating the impact for the newest versions. YMMV, don't believe everything you read on the internet, etc.

Re:Microsoft Replaces Command Prompt with PowerShell in Late... by JeffreySnover on Friday November 18, 2016 @09:09PM (#12991610)
That is a good tip. There are certain product teams that produced ENORMOUS objects and your suggestion helps when dealing with that.

Jeffrey Snover [MSFT]

Re:Microsoft Replaces Command Prompt with PowerShell in Late... by brazzledazzle on Saturday November 19, 2016 @10:58PM (#12997188)
Upon reading that again maybe I should have said it's weakness is that it's easy for everyone involved to create objects that use a lot of memory. I'm not sure it's fair to say PowerShell itself is bad at utilizing or managing memory. It's more of a possible negative side effect of one of its great strengths.
Re:Microsoft Replaces Command Prompt with PowerShell in Late... by youdontknowtho on Friday November 18, 2016 @08:54PM (#12991557)
That's great advice, man. Cheers.
Re:Microsoft Replaces Command Prompt with PowerShell in Late... by UK-AL on Friday November 18, 2016 @12:31PM (#12988394)
Most likely because it loads it all into memory, rather than say streaming it.
Re:Microsoft Replaces Command Prompt with PowerShell in Late... by copperx on Saturday November 19, 2016 @03:08AM (#12992546)
That's how I would expect MSFT to build it.
Re:Microsoft Replaces Command Prompt with PowerShell in Late... by ashmud on Friday November 18, 2016 @10:54AM (#12987572)
This bit me badly when trying to pipe GPG output. I ended up building a command string and sending it to cmd. :|
Re:Microsoft Replaces Command Prompt with PowerShell in Late... by Tarean on Saturday November 19, 2016 @05:25AM (#12992806)
That is odd, powershell shells out to cmd.exe if you try to pipe binary or text data. It goes back to powershell only if you use powershell commands in the pipeline.

If you don't pass the flags zo handle it as binary in those cases stuff breaks.

Re:Microsoft Replaces Command Prompt with PowerShell in Late... by melolife on Friday November 18, 2016 @11:37AM (#12987973)
I found out yesterday that `Select-String`, PowerShell's "grep equivalent" expands tab characters to spaces.
Re:Microsoft Replaces Command Prompt with PowerShell in Late... by brainfire on Friday November 18, 2016 @09:17AM (#12986879)
Haven't tried in the preview build but this is still the case in the recent Windows 10 build I have.
Re:Microsoft Replaces Command Prompt with PowerShell in Late... by elchief on Friday November 18, 2016 @03:03PM (#12989657)
Powershell drove me to Mac
Re:Microsoft Replaces Command Prompt with PowerShell in Late... by jodrellblank on Friday November 18, 2016 @12:36PM (#12988434)
Get-Content test.jpg -Encoding Byte -ReadCount 1000 | Set-Content test2.jpg -Encoding Byte

Piped binary data, not corrupted, since a long time before that blog post was written.

What you can't do is run native commands, and read their standard output as a byte stream without going through .Net and Start-Process.

Re:Microsoft Replaces Command Prompt with PowerShell in Late... by 1wd on Friday November 18, 2016 @12:37PM (#12988445)
Was super fun to learn about this when restoring the "backup" dumped via pipe in a powershell script.
Re:Microsoft Replaces Command Prompt with PowerShell in Late... by nolok on Friday November 18, 2016 @01:06PM (#12988704)
While the first rule of backup is "do them", the second rule is "test them". If your backups are bad and you only notice it when it's time to restore, you only have yourself to blame.

"The backups fail to restore" is such a common occurrence, it's really scary.