News for hackers. Stuff that matters.
Re:Two Months with Powershell on a Unix by dijit on Thursday April 23, 2020 @06:32PM (#22962318)
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.

Re:Two Months with Powershell on a Unix by m0xte on Thursday April 23, 2020 @06:50PM (#22962485)
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.

Re:Two Months with Powershell on a Unix by munchbunny on Thursday April 23, 2020 @07:44PM (#22962976)
Where does that happen for you?

In my experience with PowerShell on Windows, you have to approach it more like interactive python with shortcuts rather than a regular shell, and once you’re accustomed it works fine. The main issue is that it doesn’t work like a classic shell, it just has some affordances to look like a classic shell in common use cases.

Re:Two Months with Powershell on a Unix by m0xte on Friday April 24, 2020 @05:49AM (#22966304)
Well it’s not the concept but the implementation that is at fault. From persistent random WinRM failures, sudden things breaking and the whole thing wrapping rancid bits of WMI and COM which leak through regularly, it’s just pain. On top of that the interface is somewhat flakey and slow. Plus some of the semantics feel like going back to circa 1995 Perl. Oh and don’t get me started on the nightmare that is script signing and security which really does nothing useful other than get in the way.

It really feels immature.

The biggest travesty is when it is integrated into something else such as ansible, packer, chocolatey etc where it will cost you a couple of days occasionally due to some obscure issue hidden behind even more layers.

Re:Two Months with Powershell on a Unix by emodendroket on Thursday April 23, 2020 @08:12PM (#22963178)
It's weird but once you get used to it I think it's cool. No more text munging!
Re:Two Months with Powershell on a Unix by danudey on Thursday April 23, 2020 @08:01PM (#22963094)
Agreed; it's a lot more like a really weird iPython than it is a drop-in bourne shell replacement with quirks.
Re:Two Months with Powershell on a Unix by freddref on Thursday April 23, 2020 @10:00PM (#22963870)
Ya I use cygwin where I can, many of the reinventions don't improve usability.
Re:Two Months with Powershell on a Unix by larntz on Thursday April 23, 2020 @06:44PM (#22962423)
I use powershell on linux occasionally. Primarily with the azure and powercli modules. For doing vmware and azure stuff I can't think of anything that hasn't worked.

If you want to do anything that would be windows only then you're right, it probably won't work.

That said, I usually have a tmux window ssh'd into a windows machine for powershell. It would be nice to be able to manage ad and exchange from a linux machine with powershell.

Re:Two Months with Powershell on a Unix by vips7L on Thursday April 23, 2020 @06:49PM (#22962467)
Invoke-WebRequest most certainly runs on linux.
Re:Two Months with Powershell on a Unix by danudey on Thursday April 23, 2020 @08:21PM (#22963246)
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"
Re:Two Months with Powershell on a Unix by vips7L on Thursday April 23, 2020 @08:35PM (#22963339)
IWR and ConvertFrom-Json are what got me hooked on powershell. No more learning complex switches for curl or crazy JQ syntax. It's all built in and makes sense.
Re:Two Months with Powershell on a Unix by earthboundkid on Thursday April 23, 2020 @09:37PM (#22963745)
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?

Re:Two Months with Powershell on a Unix by jve on Thursday April 23, 2020 @09:53PM (#22963830)
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 by ct520 on Friday April 24, 2020 @12:35AM (#22964685)
There is an param to declare response type parsing and if you want to use different parsing. Older versions of powershell use IE and webrequest will randomly barf. It really sucked. You can also use a rest request method that uses json.net to deserialize I believe .
Re:Two Months with Powershell on a Unix by dijit on Thursday April 23, 2020 @07:20PM (#22962759)
I just attempted to prove you wrong, but it does look like it's fixed.

So is creating secure strings.

Cool!

Re:Two Months with Powershell on a Unix by jodrellblank on Thursday April 23, 2020 @09:15PM (#22963599)
Creating secure strings isn't exactly fixed; the type exists but they aren't encrypted in memory on Linux because it doesn't have the DPAPI (Data Protection API) from Windows:

https://github.com/PowerShell/PowerShell/pull/9199

Re:Two Months with Powershell on a Unix by zovin on Friday April 24, 2020 @08:51AM (#22967402)
Same here. I love using pwsh 7 on windows, but on Linux it was a whole different experience. Granted I was trying to use it on an Arch instance, which isn't technically supported, but I couldn't even get PSGet or PsReadLine to work. However, I was pretty great to run the same scripts cross OS with basic commands like Invoke-WebMethod/Invoke-RestMethod
Re:Two Months with Powershell on a Unix by pgsbathhouse2 on Thursday April 23, 2020 @08:16PM (#22963208)
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.

Re:Two Months with Powershell on a Unix by bishalb on Thursday April 23, 2020 @09:54PM (#22963836)
Can you give any example? This hasn't been my experience.