Live data from Hacker News

PowerShell is open sourced and is available on Linux

azure.microsoft.com

621–630 of 790 posts

Re: PowerShell is open sourced and is available on Linux

#621
post #256

Earlier quoted context omitted.

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 task…

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

    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

#622
post #616

Earlier quoted context omitted.

> And the over-verbose syntax doesn't help This is basically the reason I have not been willing to put any time even trying to learn ps. I mean, trying to translate unzip file.zip folder To ps was a nigthmare. Like: [System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath) I don't _want_ to learn to type stuff like that for simple shell scripts.

But that's picking an example where a. You can still use the native binary just as well. Especially in this case. b. There was no PowerShell cmdlet for it at the time. There also isn't one for executing Python code, you still have to call python. Or, if you're so inclined, load up IronPython's assembly, and use an overly verbose .NET method call ... c. There now is a cmdlet for doing so: Expand-ZipFile. I'm actually…

That was picking an example from my previous try to work with ps. I was not the admin of the server so no installation of extra programs. Or upgrading ps to the newest version.

The shell scripting I have needed has been typically very simple. Like schedule to copy this file from that server and run this command.(what was precisely all that I was trying to achieve the last time, only the file was compressed. Would have done with .bat, but that was even more difficult) As you say, using it as a glue and build the complexity to the programs behind the shell.

Re: PowerShell is open sourced and is available on Linux

#623
post #24

Earlier quoted context omitted.

Or just be sane and use ctrl-r and search.

I also highly recommend enabling the pgdn/pgup bindings for history-search-forward/backward. If you are searching for a prefix it's a bit easier than ^R.

I bound these under C-n and C-p. Very convenient indeed!

Re: PowerShell is open sourced and is available on Linux

#624

Earlier quoted context omitted.

It is just another tool in the toolchest. As you know, on Linux, there are tons of great interactive shells and it is sortof a lifestyle choice. You might want to kick the tires and see whether it fits your lifestyle or not. If you use Bash as your shell, think of PowerShell as you would python or perl - something you write scripts in and call from Bash. Jeffrey Snover [MSFT]

does powershell compile to IL? is it possible to create stand-alone executables from it that do not depend on the runtime?

PowerShell is interpreted, as far as I know. Class declarations may be compiled on the fly, but I've never used them; I'm basically still at PowerShell v3/v4.

Re: PowerShell is open sourced and is available on Linux

#625

Earlier quoted context omitted.

All those sysadmins would have been perfectly happy with just a properly working unix like shell.

Yes. Like all those early car buyers would be perfectly happy with faster horses.

And everybody remembers how Ford was forced to reintroduce a carriage with a horse a couple of decades later because nobody was really using those horseless carriages. Right?

https://blogs.windows.com/buildingapps/2016/03/30/run-bash-o...

Re: PowerShell is open sourced and is available on Linux

#626
I'm something of an OO zealot and I'm a C# developer so I'm familiar with PS and probably it's target audience so to speak.

PS is a fantastic product but I just find it too verbose. When everything is expressed as an object with properties you need to reference the object and the appropriate property. I know there are alias' for common Bash operations and idiomatic PSallows shortcuts but most people who use PS for short spells to automate something are unlikely to be adopting idiomatic styles.

For PS to gain traction I feel like it needs to be a superset of Bash and offer an easier, intuitive gateway. I know it has enormous potential, I know it has massive capabilities but still I only reach for it as a last resort. I don't think I'm alone in the matter :/

Re: PowerShell is open sourced and is available on Linux

#627

>We will be extending the PowerShell Remoting Protocol (MS-PSRP) to use OpenSSH as a native transport. Users will have the option to use SSH or WINRM as a transport. Is possibly an even bigger announcement (this means there's actual momentum behind https://github.com/PowerShell/Win32-OpenSSH )

https://github.com/PowerShell/Win32-OpenSSH/releases

Microsoft has an SSH server for Windows right now.

[Edit] Here is a guide from the WinSCP peeps on how to get it running. https://winscp.net/eng/docs/guide_windows_openssh_server

The native SFTP works well!

Re: PowerShell is open sourced and is available on Linux

#628

Earlier quoted context omitted.

This is why I find PowerShell to be an answer to a question nobody asked. If bash/zsh isn't cutting it for you, drop into something like Python, Ruby or Perl to do the heavy lifting. PowerShell will never accumulate a library as comprehensive as what any of those three have, each has had decades to accumulate packages of all kinds, and more are still being added. It's odd, but not surprising given their history of "N…

> This is why I find PowerShell to be an answer to a question nobody asked. If bash/zsh isn't cutting it for you, drop into something like Python, Ruby or Perl to do the heavy lifting. How are Python/Ruby/Perl going to give you structured objects from "ps"? That's the promise of object-based pipes. You can get useful records out of your command-line tools without having to write an ad-hoc regex.

For the most common use cases there would be a standard function to get structured objects, in Python you have os.listdir() instead of ls, etc. If there is none then you can call ps and parse the result manually or call the system functions with c interop.

Re: PowerShell is open sourced and is available on Linux

#629
post #290
post #275

Earlier quoted context omitted.

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 ~]$

Correction then: ip addr | grep "inet " | cut -f 3 -d " "

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

#630
post #57

Earlier quoted context omitted.

Ok, that sounds good. But what if some developer decided that some field would have prefix "ABC" in all values, then the value I am interested in, then some value I am not interested in at the end? (you say this can't happen? Clue: WMI.) Can I take the value, convert it to string, make some magic on it and convert it to another object entirely? I don't know, I never had any problems with text parsing. I love strong t…

The default regex functionality is absolutely terrible (maybe this can now be fixed with a PR). You'd write your own cmdlet[1]. A few things are demonstrated in the cmdlet: functions that take pipes, functions that return pipes, anonymous functions, actions to perform before processing a pipe and dynamic objects. The Powershell syntax gets ridiculed for being ugly, but it's beautifully expressive. > Can I take the va…

The default regex functionality is absolutely terrible

How so?

Post reply on HN