6 ms·
I only discovered Powershell recently, and it's impressed me how "batteries-included" it is. Like, I can access the GitHub API, download the latest release of a
by publius_0xf3 3y ago
I only discovered Powershell recently, and it's impressed me how "batteries-included" it is. Like, I can access the GitHub API, download the latest release of a program, and decompress it, with progress indicators shown throughout, all without importing a library. At times, it feels more Pythonic than Python.
But jeez, the syntax. There's a lot to say, but the worst is that I'm never sure where I need to place parentheses. By making brackets in function calls optional, it just makes you end up writing Lisp-like code when the arguments are also function calls or arrays. You are forced to write parenthesized function calls anyways when invoking .NET commands, so they might as well make it universal instead of this chimerical compromise. It's a similar story with quotation marks around strings.
But it speaks to the strengths of the language that I still enjoy writing it anyways.
- lazypenguin 3y agoPowershell is underrated and I actually prefer it over bash but indeed the syntax can be a slog sometimes. I used it a lot but I never felt I was “fluent” and found myself usually often needing the docs for even basic syntax (for loop, function params, etc.) Also in my experience I found some of the limitations surprising, having to call .NET methods was not uncommon for me. Regardless I’m happy to never write a batch script for the rest of my life, powershell is definitely an upgrade.
- tmn 3y agoMy main use for llms has been to finally start making power shell scripts
- pixl97 3y agoHeh, so much so. I'll have gpt make a series of loops and evaluators and then come back and put the my logic in the placeholders. The other thing I find is by thinking out the process of what I need and communicating to the LLM is I tend to make better scripts that have more functionality since I'm thinking about what I want done, and not thinking about just getting the syntax correct.
- Eisenstein 3y agoIt is great for doing something like 'write a script that recursively goes through all the directories and finds pictures which were taken between <date> and <date> and copy them to <directory> then sort them in subdirectories by month and day.' So much tedium is now easy if I can remember 'powershell can do it, and GPT can write it for me'.
- yndoendo 3y agoI really do not see powershell as a bash, zsh, fish, ... shell equivalent. It is more inline with perl, python, php, ... scripting languages. One thing I really dislike about powershell development is default aliasing such as using curl to actually call Invoke-WebRequest. This was such bad taste and disrespectful to the actual application and their developers that make a really good library and tool. Windows even now comes with curl.exe in C:\Windows\System32.
- deleted 3y ago[deleted]
- uxp8u61q 3y ago> One thing I really dislike about powershell development is default aliasing such as using curl to actually call Invoke-WebRequest. Hasn't been a thing for a while now.
- electroly 3y agoWhile it's true that it's no longer aliased in PowerShell 7, the currently shipping version of Windows PowerShell included in Windows 11 still aliases it to this day. If you intend to be portable across both versions, you still have to use "curl.exe" to get the real curl.
- jodrellblank 3y agoFunction calls don't need parens because it's an interactive shell, and nobody writes Bash or Command prompt lines like: user@server$ grep('word', 'file.txt') C:\ > notepad.exe() And if they did make that the requirement it would be an instant dealbreaker for a lot of people coming from other shells. It is indeed a similar story with quotation marks around strings, in that you don't want to have to write: user@server$ grep 'word' 'file.txt' when you could write user@server$ grep word file.txt If the parser can tell from the context that the next token should be a string, it will read it as a string. If it can't tell, and the next token might be a command but you want it to be a string, then you have to quote it. If there's a space e.g. in the file path and you want it to be read as a single token, you have to quote it. Always quoting won't break anything, it's just unnecessary.
- benbristow 3y agoI've often gotten caught out using commas to separate arguments like most other scripting languages ever. One of those things you need to remember when writing Powershell scripts!
- jodrellblank 3y agoCan you give an example of where/how? I imagine you don't get caught out writing Bash scripts like: grep -e,-i,'\bneedle\b',file.txt | cut -F,2,-d,':' Because that's so contextually distinct from Python/JavaScript/Ruby; in shells (and APL, J, LISPs), arrays of commands and their arguments are space separated rather than comma separated. Similar in PowerShell, where it looks like shell it tends to work like shell: get-childitem -Path c:\ -Filter *.txt -Force Where it looks like scripting language it tends to work like one: $host.ui.WriteLine('Green', 'Yellow', 'Hi')
- benbristow 3y agoWith functions function Get-Something { Param ( [Parameter(Mandatory=$true, Position=0)] [string] $Name, [Parameter(Mandatory=$true, Position=1)] [int] $Id ) # Write the output to the console Write-Output "Name: $Name, Id: $Id" } Get-Something "Alice" 42 If you were to call Get-Something("Alice", 42) It would pass "Alice", 42 to the first parameter. You can use named parameters to get round this, e.g. Get-Something -Name "Alice" -Id 42 Still a bit of a gotcha!
- goodbyesf 3y ago> I only discovered Powershell recently, and it's impressed me how "batteries-included" it is. Meh. Powershell, like most things windows, is just a dumbed down version of its unix equivalent to cater to its 'lower-skilled' user base. The best thing about powershell is its documentation and help section. It's far more 'detailed' and far more examples than its unix counterpart. How many times do you just wish a man page just had an example that you tinker with to get what you want? With powershell, you get that. Another thing going for powershell on windows ecosystem is that microsoft is tying powershell with their servers to make administration simpler and easier. But powershell certainly isn't python or perl.
- hwayne 3y agoI used to write a lot of bash and fish and I find Powershell has a much higher skill ceiling.
- bheadmaster 3y ago[flagged]
- hwayne 3y agoI read that as "I don't know what a skill ceiling is".
- bheadmaster 3y ago[flagged]
- jodrellblank 3y ago> "How many times do you just wish a man page just had an example that you tinker with to get what you want? With powershell, you get that" Two sentences ago you said helping people was dumbing down for low skill users. Hmm. > "Another thing going for powershell on windows ecosystem is that microsoft is tying powershell with their servers to make administration simpler and easier." They have been untying PowerShell from their servers for 7 years. PowerShell current version doesn't ship with Windows and does run on macOS and Linux. > But powershell certainly isn't python PowerShell has a good interactive shell, better/more convenient introspection/reflection, integrates more thoroughly with its underlying language (C#), has more humane defaults (case insensitivity).
- velid0 3y agoA few days ago I've tried to set four aliases to some files with calling a simple function. I took about an hour with help of chatgpt and still I'm not sure how things works.
- electroly 3y agoAgreed. Coming from C# and from traditional Unix shells, PowerShell feels like it was made competently but with no aesthetic taste whatsoever. It's got a syntax only a mother could love. But its flexibility and usefulness can't be denied. It's just... ugly.
- jiehong 3y agoJust been trying Nushell and comparing it to Powershell, and you can clearly feel the inspiration, except that everything is a table or a list of record instead of their own special objects. It makes the syntax quite a lot cleaner, albeit sometimes less convenient, but more coherent. With Powershell Core being the same on Windows, Linux and Mac OS, I find it much better to write small scripts with it, and more portable too. Never have to find out that the options to sed or another utility isn’t the same on macOS vs Linux for example.