News for hackers. Stuff that matters.
Re:PowerShell is open sourced and is available on Linux by ksk on Thursday August 18, 2016 @01:22PM (#12314477)
Could you elaborate on what the actual complexity is, rather than what you imagine?

For a developer writing a tool, exposing an interface as objects is far easier than having to constantly serialize data into a string. Keep in mind that once you serialize data into a string, you can never change the order of the data or else other tools will break. Not so with a object based interface.

In other system-admin type tasks PowerShell hides complexity. For e.g. finding the IP address of a network interface is simply

  Get-NetIPAddress | select IPAddress
compared to something horrendous like

  ifconfig | perl -nle 's/dr:(\S+)/print $1/e'
Re:PowerShell is open sourced and is available on Linux by ubernostrum on Thursday August 18, 2016 @08:13PM (#12317174)
As someone who recently got his first exposure to PowerShell, I'll chime in that the case I needed to deal with was one where it added complexity.

In summary:

I need to pull data from a company we're partnered with, and get it into our systems. They ship it as SQL Server backup files. OK, no big deal, we can mount those up and run queries to dump stuff out to whatever format we like and ingest it.

Except part of that data is files, which were stored in the DB as binary blobs (in a table along with filenames and metadata). Need to get those out of there and into our storage as real files. OK, no big deal, I can just query for filename and file contents, dump out onto disk and then batch-transfer into our archival storage, right?

Except no matter what kind of obvious shell-idiom method I try to use, it doesn't work because PowerShell stubbornly insists that I must be working with text data when I'm using all those handy shell constructs, and so the files end up corrupt.

So now instead of just being able to shove data through pipes like I would on Unix (which, for all its faults, doesn't really care whether I'm sending binary or text data), I have to have my script go and instantiate objects for creating a file and reading and writing binary streams, and remember to clean up after them, and my script ends up way more complicated.

What would have been a pretty simple script anywhere else now has to know a bunch of .NET libraries and how to create and work with their types, and that's less useful to me.

Re:PowerShell is open sourced and is available on Linux by ksk on Friday August 19, 2016 @02:13PM (#12322101)
Its true that powershell being a new tech probably doesn't have the large library of "known ways" to do things that the UNIX world has. And BTW I'm not even a powershell person. I write embedded software in C++ for a living ! Having said that, I'd imagine you would parameterize something like

  Invoke-Sqlcmd -Query "SELECT ..." and write it out to a file? 
or avoid it and just use BCP "select blah" queryout "c:\file.jpg" etc etc
Re:PowerShell is open sourced and is available on Linux by se6 on Thursday August 18, 2016 @01:38PM (#12314653)
What about:

    ip addr show | grep inet
Edit: wrote back original command and replied below instead
Re:PowerShell is open sourced and is available on Linux by ksk on Thursday August 18, 2016 @01:41PM (#12314676)
That doesn't work on my CentOS box.

  [kapil@localhost ~]$ ip addr show | grep inet
      inet 127.0.0.1/8 scope host lo
      inet6 ::1/128 scope host
      inet 192.168.128.236/24 brd 192.168.128.255 scope global dynamic eth0
      inet6 fe80::215:5dff:fe80:501/64 scope link
  [kapil@localhost ~]$
Re:PowerShell is open sourced and is available on Linux by se6 on Thursday August 18, 2016 @01:56PM (#12314810)
Correction then:

    ip addr | grep "inet " | cut -f 3 -d " "
Re:PowerShell is open sourced and is available on Linux by ksk on Thursday August 18, 2016 @01:58PM (#12314837)
It still doesn't work (you forgot to add the tr back in your reply after your edit)

  [kapil@localhost ~]$  ip addr | grep "inet " | tr -s " " | cut -f 3 -d " "
  127.0.0.1/8
  192.168.128.236/24
  [kapil@localhost ~]$

To be honest, I don't consider this to be that bad, I was just replying to a person who thought that bash was "simple", and powershell was "complex". Also, I don't have a problem with either tool. I'm very open to the idea that Microsoft can and does create awesome tech, despite having other shitty products.
Re:PowerShell is open sourced and is available on Linux by se6 on Thursday August 18, 2016 @03:28PM (#12315639)
Thanks, too many edits indeed!
Re:PowerShell is open sourced and is available on Linux by Too on Friday August 19, 2016 @03:13AM (#12318415)
Nice way to prove the point that object based is far more reliable than text based.
Re:PowerShell is open sourced and is available on Linux by lottin on Thursday August 18, 2016 @02:59PM (#12315354)
ip addr | awk '/inet / { print $2 }'
Re:PowerShell is open sourced and is available on Linux by ksk on Thursday August 18, 2016 @03:05PM (#12315427)
That doesn't work either.

  [kapil@localhost ~]$ ip addr | awk '/inet / { print $2  }'
  127.0.0.1/8
  192.168.128.236/24
  [kapil@localhost ~]$
You guys are just proving my point. _I_ already know how to do it using bash. Its just that using objects and querying properties is far simpler. And I just took a random example because its a common thing that someone would want to do.
Re:PowerShell is open sourced and is available on Linux by brazzledazzle on Thursday August 18, 2016 @06:55PM (#12316876)
You really couldn't have asked for a better chain to demonstrate the validity of your point. Having been blinded by my own world view and biases in the past I sympathize with them but this is too funny not to have a little laugh at their expense.
Re:PowerShell is open sourced and is available on Linux by kondor6c on Thursday August 18, 2016 @10:04PM (#12317539)
I think what others might be demonstrated is that there isn't a reliance on what object Microsoft decides to ship to you, in *nix we can combine commands and builtins and get the information in the structure we need without having to wait 8 months for a system reboot (or worse a paid for upgrade) that will give us what we need.
Re:PowerShell is open sourced and is available on Linux by 59nadir on Friday August 19, 2016 @01:28AM (#12318134)
Well, to be fair, what was demonstrated here was that people didn't actually extract the data after multiple edits and tries, regardless of what tools they had at their disposal.

I think the idea of an object pipeline is sound for precisely this reason, but I don't think it should be connected to any one language or platform.

Re:PowerShell is open sourced and is available on Linux by ksk on Friday August 19, 2016 @11:38AM (#12320797)
First of all you are incorrect in your assumptions. You are reliant on the author of the tool in both cases. Just as there is no "UNIX Person" who decrees that all executables on UNIX must output text, there are vendors other than Microsoft who write software for Windows. You can write one too, it takes about 5 minutes to expose a powershell interface. And I'm not even a .NET developer. I write embedded software for a living.
Re:PowerShell is open sourced and is available on Linux by JoBrad on Thursday August 18, 2016 @01:59PM (#12314848)
But once again, you're simply scraping text, instead of querying an object for properties.
Re:PowerShell is open sourced and is available on Linux by dzamo_norton on Thursday August 18, 2016 @02:25PM (#12315088)
It is parsing text, but that text does have some consistent structure. Contained within it are properties. One can make the same comment of reading JSON or XML but I'll admit those are more like what you'd choose for an API. In general there is a not-entirely-obvious (to me) question of where does "formatted for machines" end, and "formatted for humans" begin? We can't say "it's for machines if and only if it must conform a schema that's defined in advance", not any more.
Re:PowerShell is open sourced and is available on Linux by pessimizer on Thursday August 18, 2016 @02:52PM (#12315301)
You would have to be aware of that fact in order to write the command. The question is about relative advantage, not about what the tools do.
Re:PowerShell is open sourced and is available on Linux by Touche on Thursday August 18, 2016 @02:31PM (#12315152)
> Could you elaborate on what the actual complexity is, rather than what you imagine?

I can only use this feature by using a .NET language. I can't take the strongly typed objects into a Node.js script, or a perl script.

Re:PowerShell is open sourced and is available on Linux by ksk on Thursday August 18, 2016 @03:00PM (#12315364)
>I can only use this feature by using a .NET language.

It goes without saying that a binary interface requires use of a system that understands that particular binary interface. With .NET being open source though, anyone is free to write a bridge to using the objects in COBOL if they wanted to.

>I can't take the strongly typed objects into a Node.js script, or a perl script.

Yes, because they have no concept of strongly typed objects. You can convert objects to strings if you're using an incompatible tool/language. I don't know what your point is. Sorry..

Re:PowerShell is open sourced and is available on Linux by Touche on Friday August 19, 2016 @08:00AM (#12319434)
The point is that this thing is less valuable by being limited to only being used by things that Microsoft created (in reality). Text, with all of its flaws, can be used by everything.
Re:PowerShell is open sourced and is available on Linux by temac on Thursday August 18, 2016 @05:35PM (#12316483)
I guess the point is the point. Potential bridges that do not exist already and probably never will do not matter -- extending that idea of potentiality I could say that you are free to reimplement the CLR in Fortran, so PowerShell is compatible with Fortran? Oups sorry you already reached that ridiculous point, only with Cobol.

Virtually any language can already input and output text. That's the real lingua franca of computing (even if it is messy and dirty), not .Net objects...

Re:PowerShell is open sourced and is available on Linux by ksk on Thursday August 18, 2016 @06:57PM (#12316886)
>Potential bridges that do not exist already and probably never will do not matter

The difference between impossible and possible is important. Please read what I was replying to. Using your argument, Anytime a project is open sourced, you could reply with "who cares about potential since nobody has actually done anything with the source". Good job.

>Virtually any language can already input and output text.

Um, you seemed to have missed the obvious point that objects can also be converted to text through powershell if the other side can only accept text. So, I don't quite know what you're complaining about. Could you detail your actual technical complaints with powershell, rather than having a philosophical argument?

>That's the real lingua franca of computing (even if it is messy and dirty), not .Net objects...

I don't agree with your opinion, nor with the idea that only a two-choice system can exist.

Re:PowerShell is open sourced and is available on Linux by Jayku1 on Thursday August 18, 2016 @06:21PM (#12316732)
That's not really true, you can serialize as json in all of those
Re:PowerShell is open sourced and is available on Linux by vasilia on Thursday August 18, 2016 @10:47PM (#12317671)
And how to delete files older 2 days? Get-Files / | select olderThan 2 | Delete-File ?

But it's not bash, it's coreutils

  find ./ -mtime +2 | xargs rm
Re:PowerShell is open sourced and is available on Linux by ygra on Friday August 19, 2016 @02:18AM (#12318258)

    Get-ChildItem -File | Where-Object LastWriteTime -lt (Get-Date).AddDays(-2) | Remove-Item
If you prefer shorter (and similarly obscure if you don't know the language):

    ls -file|? LastWriteTime -lt ((date)+'-2')|rm
I actually find PowerShell's version more readable, even if more verbose. But code is written only once and read a lot of times. I may not know what the +2 actually means with the -mtime argument. How would I change it to look for the age of two hours instead of days?
Re:PowerShell is open sourced and is available on Linux by vasilia on Friday August 19, 2016 @01:24PM (#12321704)
> I actually find PowerShell's version more readable, even if more verbose.

Sorry, I can't agree with you.

> I may not know what the +2 actually means with the -mtime argument. How would I change it to look for the age of two hours instead of days?

If you forget or doesn't know what is mtime, you can open man find. For less granularity than days use mmin.

Re:PowerShell is open sourced and is available on Linux by ksk on Friday August 19, 2016 @02:12PM (#12322077)
Just as an aside (and this probably applies to powershell as well), what if you have mapped folders from multiple servers into your file system and those servers are in different timezones? Something like

  /Mapped-Temp-folders/Server-Asia/temp
                      /Server-UK/temp
                      /Server-Japan/temp
I guess the script wouldn't work then if you wanted to clean out data older than 2 days, as per their timezone.
Re:PowerShell is open sourced and is available on Linux by useerup on Friday August 19, 2016 @11:00AM (#12320479)

    ls|? LastWriteTime -lt (date).AddDays(-2)|rm
Re:PowerShell is open sourced and is available on Linux by kondor6c on Thursday August 18, 2016 @10:00PM (#12317526)
I just now have the chance to use Powershell on Linux, with that Powershell command you demonstrated, I get a command not found.