Live data from Hacker News

Two Months with Powershell on a Unix

code.joejag.com

31–40 of 113 posts

Re: Two Months with Powershell on a Unix

#31
post #17

Earlier quoted context omitted.

This comment made me go and try out Invoke-WebRequest because I'd forgotten what it was like. Being able to do simple web scraping like this in a "shell" is pretty great: $hn = Invoke-WebRequest https://news.ycombinator.com/ $hn.AllElements | Where {$_.TagName -eq "a" } | Where { $_.Class -eq "StoryLink" } | select "innerHtml"

FWIW, I already have a command line tool that can do that installed in regular Unix: https://github.com/ericchiang/pup The docs even use the same example of scraping HN. How does Invoke-WebRequest decide if it’s looking at HTML or something else?

Well, you use Invoke-RestMethod for JSON/XML stuff.

Or decide yourself for Invoke-WebRequest to pipe it with whatever the data: ConvertFrom-{JSON,XML,CSV}

With Invoke-WebRequest you get back headers, raw response, etc - and you get to decide whats next. With the RestMethod - just the content as an object.

Re: Two Months with Powershell on a Unix

#32
post #2

Dude has more patience than me. I tried running powershell on linux a few times, and every single time the second command I run is not supported on linux. I don't even remember what the commands were, PSremoting was one for sure and I think another was Invoke-WebRequest. Powershell on linux is a nice idea but in the current form it is in name only, as nearly nothing works.

Invoke-WebRequest doesn't even work correctly on windows for a large amount of very vanilla web functionality. Powershell is a nice idea, but Microsoft is kidding themselves if they think it's even close to the alternatives.

Can you give any example? This hasn't been my experience.

Re: Two Months with Powershell on a Unix

#33
>For example, if we wanted to get the first three files from ls I’d do something like `ls | head -n 3`. In Powershell, it’s `$(dir)[0..2]` since the dir command is returning an array which I can index into.

You could do that, but the way to write it in the bash way would be `dir | select -first 3`

>a quick Google told me to use `echo | openssl s_client -showcerts -servername joejag.com -connect joejag.com:443 2>/dev/null | openssl x509 -inform pem -noout -text` which works fine in Bash or Zsh. Still, in Powershell, it throws an error for some reason.

It won't throw an error (unless you're running it without a tty), but it will ask you to enter the parameter of `echo`. That's because `echo` aka `Write-Object`'s parameter is required, unlike bash's `echo`. `echo |` in bash is the same as `

    $null | openssl s_client -showcerts -servername joejag.com -connect joejag.com:443 2>/dev/null | openssl x509 -inform pem -noout -text

Re: Two Months with Powershell on a Unix

#34
post #5
post #2

Dude has more patience than me. I tried running powershell on linux a few times, and every single time the second command I run is not supported on linux. I don't even remember what the commands were, PSremoting was one for sure and I think another was Invoke-WebRequest. Powershell on linux is a nice idea but in the current form it is in name only, as nearly nothing works.

I’m not sure I could cope with that. I have enough problems with it on windows. Literally every corner you turn something punches you in the balls or turns to dust in your hands. It’s one of the most frustrating things I’ve ever used and I avoid it where I can. I would not invite it onto a *nix machine voluntarily where there are established patterns and solutions which have matured over the space of 40 odd years now…

Ya I use cygwin where I can, many of the reinventions don't improve usability.

Re: Two Months with Powershell on a Unix

#35
post #8

I've been using Unix for 20+ years, switched to pwsh as my main shell 4 years ago (on both Windows and macOS). Here's my notes: https://github.com/mikemaccana/powershell-profile/ Last few weeks I've been going back to bash, mainly to try out WSL/Ubuntu's defaults, but will probably move to pwsh there too. I like the consistent naming (which means I can guess commands) and avoiding the scraping that's inherent in text…

Just a tip. If you want something like sudo, install gsudo (choco install gsudo). It works like sudo: no new shell, don’t need to use “”.

Re: Two Months with Powershell on a Unix

#36

I am dead serious. Powershell should replace (bash) shell scripting under any Linux. I find shell scripts terrible, I've learned to switch to Python quickly, despite the overhead. Powershell is very command-line friendly, with easy tab-completion of commands. I've worked with it extensively on Windows, creating large worklflows with it, it's very nice. Powershell even has a unit test tool called 'pester' which is fun…

powershell is ok, I guess, but the core issue is it's over-engineered. Bash is weird, but it is everywhere and it's simple, and that simplicity is going the be very difficult to replace. How do replace nothing? I love Python, do switch to it. ( The windows and MS stack is utter balls )

> the core issue is it's over-engineered.

I wouldn't call it over-engineered. Ambitious? Maybe, but I don't see PowerShell lagging behind in any front it's designed for.

Re: Two Months with Powershell on a Unix

#39

>For example, if we wanted to get the first three files from ls I’d do something like `ls | head -n 3`. In Powershell, it’s `$(dir)[0..2]` since the dir command is returning an array which I can index into. You could do that, but the way to write it in the bash way would be `dir | select -first 3` >a quick Google told me to use `echo | openssl s_client -showcerts -servername joejag.com -connect joejag.com:443 2>/dev/…

A) this is all good stuff, I want to get better with powershell in 2020 and just learned some things here B) I think the authors point was that a lot of their googling for how to do things in a shell assume posix shell. So copy paste from web doesn’t work as well for powershell, which becomes frustrating for new onboarders.

Re: Two Months with Powershell on a Unix

#40

I like that it passes objects instead of strings, I could see that being really useful. Get-Member will list all methods and properties of an object.

My new favorite recipient of objects is Out-ConsoleGridView (along with the normal gridview).

https://devblogs.microsoft.com/powershell/introducing-consol...

Post reply on HN