10 ms·
Getting work done with PowerShell on Linux
- cynicalsecurity 4y ago[flagged]
- pipeline_peak 4y ago"PowerShell became a huge reason why Microsoft was able to succeed in the cloud computing market" um...Really?
- sofixa 4y agoNope, there's no way that's true. Microsoft is only succeeding in cloud computing based on their existing reputation and business relationships, and software they managed to port as a service (O365). Without those their cloud would have crashed and burned as the buggy, slow, unreliable, insecure [1] mess that it is. 1 - if you feel like disputing the security record of Azure, they're literally the only big public cloud with more than 0 (and multiple at that!) critical cross-tenant security vulnerabilities, at least some of which were extremely trivial to exploit.
- zahrc 4y agoNo, not really. The PowerShell modules for the several M365 admin centres are, including the “new” MSGraph API, buggy, inconsistent and missing vital features across the board. PowerShell is great, MickeySofts own modules, not.
- lc9er 4y agoYeah. They've repeatedly bungled Azure/O365 related Powershell modules. Some modules offering partially overlapping functionality, which are then deprecated in favor of MSGraph. The Powershell MSGraph API is not a 1:1 replacement and the documentation for Powershell is pretty awful in places.
- Decabytes 4y agoThis interpretation was based off of this tweet by Snover^1 > A couple of years ago and senior exec told me that PowerShell was THE technology that enabled Microsoft to move to the cloud. > He said that Exchange lead the way and that it could never have done it if weren’t for PowerShell. > I had never heard that perspective. But liked it. Maybe I'm misinterpreting it, or he is stroking his own ego, but there at least is one source for it 1. https://twitter.com/jsnover/status/1523020982490832896 https://twitter.com/jsnover/status/1523020982490832896
- dopylitty 4y ago“Cmdlets return objects not text, making it easier to access specific components of the returned object” This is for me the key value of shells like PowerShell. Uncountable billions of person hours have been wasted parsing the text output of common *nix commands. It’s time to move away from the “everything is text with random formatting” philosophy.
- bheadmaster 4y agoThat only works if there is a type of object for each and every type of output you will ever need. In my experience, there are often commands which just output text, and I need to parse them somehow, which leads to an awkward flood of Out-String | { $_ | Select-String -Pattern "etc." } type commands which are hard for me to get right. Perhaps that's just a reflection of my lack of experience with PowerShell, but assuming commands have a stable CLI interface (which most commands do in the *nix world), it's much easier for me to simply parse things with sed/awk/grep.
- Pet_Ant 4y ago> That only works if there is a type of object for each and every type of output you will ever need. Everything returned by the built-in commands is. If you are calling some executable, yeah, then you'll need to wrap it. I do recommend wrapping commonly used executables with things that return PowerShell objects. Tedious at first but as you build up over time you find yourself straying into string parsing less and less.
- crabbone 4y ago> I do recommend wrapping commonly used executables with things that return PowerShell objects. I'd better spend my time writing a different shell. This sounds like a life-long with ever increasing number of bugs nightmare to support kind of project.
- injidup 4y agoAnd what would your different shell do with a command that just returned plain text. You have the same parsing problem. Powershell gives you a standard object system to work with that if you lift stuff into are then available to everything else. With text shells everyone ends up writing a different parser each time for each small script.
- fnovd 4y agoVery cool, but even so it's hard to see the benefit of learning PowerShell just for Linux. Interacting with objects instead of text is definitely a huge plus. However, the main benefit of bash is the portability. If you have to set up a special scripting environment on every machine you're working with, you're better off setting up something with a "proper" language instead (as noted by the author). If I'm willing to give up the ability to dump my script in an unconfigured environment and have it work, PowerShell is nowhere near the top of my list. If you spend most of your time in the Windows ecosystem, then there's no reason not to learn it. If I had cut my chops with PowerShell instead of bash I'm sure I'd be clamoring for some kind of LSW system. There's a reason why things went the other way, though. I don't think we're going to get Rust bindings for C, either.
- Pet_Ant 4y ago> However, the main benefit of bash is the portability This was the reason why I learned PowerShell. It is the only shell that works on Windows/Linux/OS X (to those who don't know, it's open source now: https://github.com/PowerShell/PowerShell https://github.com/PowerShell/PowerShell ). Every team I join is a mix of Windows and Mac users with the occaisional Linux user. This is the only shell that you can use to across all three without compromise. Otherwise I find that whatever platform is dominant writes the helper scripts and the others get shrugs and "figure it out". Now, you could try to write them in Python, which isn't the worst idea, but it's not a shell.
- qclibre22 4y agoIs it installable using vanilla-esque yum or apt?
- adzm 4y agoIt needs the Microsoft repository registered if it is not already. Then you can just do the usual apt commands.
- Kon-Peki 4y agoIt's available as an Ubuntu snap. Not exactly what you are asking for... It's intentionally different than UNIX shells. If you are expecting UNIX shell behavior you will not like it. I have to use it at work for Windows stuff. It is amazing. But I would never install it on my home computer because I don't trust all the other Microsoft stuff that comes along with it. There is one big complaint that I do have with it - working with massive (multiple gigabyte) files is a pain. It wants to load the entire file before doing anything; most likely because it wants to treat everything as an object - therefore it has to build the objects before it can work with them.
- bheadmaster 4y ago[flagged]
- DrThunder 4y agoFunny, I'm doing almost exactly the opposite in MacOS currently. I'm mostly a windows admin and I love powershell for administering windows PC's. I've got enough Macs to take care of now that I just got an M2 MacBook. I'm attempting use the MacBook as my everyday driver. Unfortunately, posh just isn't all that useful on the Mac... I can't remote into windows machines or run any AD utilities so I'm stuck using a windows VM or remoting into another windows machine to run my stuff ha ha.
- bheadmaster 4y agoIf you have time, I'd deeply recommend learning Bash. It's a native shell on any *nix system, including MacOS, so it's much more ergonomic to work with, once you get into it. This is a book that gives a gentle, yet thorough introduction to the topic: https://tldp.org/LDP/Bash-Beginners-Guide/Bash-Beginners-Guide.pdf https://tldp.org/LDP/Bash-Beginners-Guide/Bash-Beginners-Gui... Of course, every tool has its context and tradeoffs. I've learned PowerShell after working with Windows administration, and it's good. Bash has a lot of shortcomings on Windows (CRLF, 0777 permissions, apt not working on my machine for some reason, etc.), so I use PowerShell. But on MacOS, I'd definitely recommend a native *nix shell.
- DrThunder 4y agoYeah I know a bit of bash. I've administered enough nix machines that I've had to use it. I haven't written in big scripts in it though, usually just a few lines for things.
- DangitBobby 4y agoIf you see this and think "being able to easily manipulate CSVs and other files in the shell would be really nice" you should definitely check out nushell.
- damagednoob 4y agoOr csvkit[1]. [1]: https://csvkit.readthedocs.io/en/latest/ https://csvkit.readthedocs.io/en/latest/
- josteink 4y agoI’ve found PowerShell the easiest way to automate and power CI/CD in a mixed Windows, Mac and Linux environment. It feels kinda weird at first, but then you install the LSP server for it in your editor, and suddenly things start feeling way more solid and reliable than bash. I’ve come to appreciate it more than I expected.
- donatj 4y ago> For some people a one-hundred-line shell script is too long. For others, that’s a regular day. But most people would probably agree that a 10,000 line shell script should probably have been written in a more robust programming language. So why the contention? I mean maybe. My big thing is single responsibility. My suspicion is if you wrote 10,000 lines of shell script that should probably be like 20+ individual scripts and you've written something with way too many responsibilities. A script should do a single thing.
- notshift 4y ago"Do a single thing" is a meaningless qualifier. Redis is 70k lines of code and yet only "does a single thing" - runs an in-memory data store. IMO it's much more useful to just consider which mode of code organization increases readability and maintainability. Those are things you can actually describe and examine.
- jmclnx 4y agoI am curious over what eventually happened to Jeffrey Snover. Was he justly compensated for his work ? Did a search, and seems he was eventually promoted: https://www.spiceworks.com/tech/tech-general/news/jeffrey-snover-quits-microsoft/ https://www.spiceworks.com/tech/tech-general/news/jeffrey-sn...
- godtoldmetodoit 4y agoHe left MS within the last year and is at Google now. He was a technical fellow at MS for the past number of years, which is their technical track equivalent of a Senior VP.
- geophile 4y agoMarcel (https://marceltheshell.org https://marceltheshell.org) is a shell designed around the idea of piping objects instead of strings, in a way that should be more familiar to Linux users. It is designed to be bash-like. Instead of learning sublanguages (awk, find, etc.), customization is done by Python, and in fact, it is Python objects that are piped between commands. To take an example from the article, here is the marcel code to read penguins.csv and get unique species values, sorted: read -c penguins.csv | map (species, *: species) | unique | sort Or to find species = 'gentoo': read -c penguins.csv | select (species, *: species == 'gentoo') "read -c penguins.csv" reads the file, but instead of returning strings, -c causes each line to be parsed into a Python tuple. In both cases, parens delimit a Python lambda (you can omit or include "lambda"). "species, *" binds species to the first value of a field, and * to a tuple of the remaining fields. So "map (species, *: species)" maps the row to just the value of the species column. "select (species, *: species == 'gentoo')" uses a Python expression to select rows with species 'gentoo'. You can also do grouping and aggregation in marcel. For example, this command locates files recursively, obtains the extension and size of each, groups by extension, and then sums sizes for each extension: ls -fr | map (file: (file.suffix, file.size)) | red . + "ls -fr" lists everything recursively (-r), yielding only files (-f). A stream of File objects is piped to map, which maps each File to an (extension, size) tuple. "red . +" does reduction (i.e., grouping and aggregation. The "." specifies that the first part of the input tuple, the extension, is used for grouping, and the second part, the file size, is aggregated using +.
- Flipflip79 4y agoObviously, this is a totally subjective opinion without much critical thought - but for me PowerShell is just...ugly. Its ugly to write, the PowerShell Terminal in Windows is aesthetically ugly (the blue, yellow, and red). Error output is verbose (good) but awfully formatted. The whole thing just makes it feel "cheap" to me. Find it really hard to get over that bias now when I need to work in PS.
- vladvasiliu 4y agoWith the new Windows Terminal you can get more pleasant colors. But of course, the syntax stays the same. And, to me, one of the worst things is how laggy it is (on an 11th gen i7 with some kind of nvme drive).
- rafabulsing 4y agoYou can change the color scheme in the classic PowerShell terminal as well: https://beebom.com/how-change-powershell-color-scheme-windows-10/ https://beebom.com/how-change-powershell-color-scheme-window...
- zokier 4y agoNobody has accused Perl, Bash, cmd, or VBscript of being particularly pretty either, and that is the company powershell is in.
- oblio 4y agoYou can change those colors in 10 seconds :-)
- sebazzz 4y agoThere is a huge difference between Powershell Core (6+, pwsh) and Windows Powershell (5, powershell.exe): pwsh: > write-error Oh-Oh Write-Error: Oh-Oh Windows Powershell: > write-error lol write-error lol : lol + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException
- jmbwell 4y agoPowershell is often underutilized. It’s absolutely worth being conversant in it if Windows or Azure are part of your environment. And being able to work directly in Powershell from my Mac is just great, versus having to remote into a Windows machine. I’m not switching all of my workflows to Powershell. That would be silly. I’m honestly not particularly inclined to use Powershell unless I have no other option. But it’s a valuable tool in the box. As are Python and (lately for me) zsh. And as with anything else, it’s worth knowing how to get the most out of it. This article isn’t bad. I also found Powershell in a Month of Lunches to be helpful at demystifying it.
- deleted 4y ago[deleted]
- aib 4y agoI would really like to try PowerShell, especially since it has a different paradigm than the "text" shells that I'm used to---but Microsoft's name behind it gives me pause. I can't rationalize it except for that every MS technology I've tried turned out to be tailored for a different class of user---lower-skilled and MS-paying. There's a high chance this itself is irrational, but if it blocks it blocks.
- thunderbong 4y agoIt's open source, in case you didn't know.
- app4soft 4y ago> For example typing… set-location ~ > On PowerShell in Linux and… cd ~ > on Windows both send you to whatever your Home directory is. Is not it vice versa? I mean, on Linux it is `cd ~` and on Windows `set-location ~`, no?
- rom-antics 4y agoThe point of that section was that those commands work the same everywhere. You can type both cd and Set-Location on both Linux and Windows and it will work.
- app4soft 4y agoIt written bad and is confusing reader, especially those who are not aware of how home . As for me, it would be better to clarify as next: > Under Linux and Windows both commands `cd ~` and `set-location ~` in PowerShell send you to whatever your Home directory is.
- majkinetor 4y agoNo. You can use both in pwsh on any OS.
- password4321 4y agoI stick with PowerShell on Windows and miss its forgiveness of case sensitivity and slash direction issues for tab complete in other shells.