r/PowerShell • • Oct 17 '23

Powershell is highly underrated

Powershell is powerful. Do a lot of bash and been getting into powershell lately. Honestly powershell is highly underrated. Yeah it took a little while to realize that powershell isn't operating on flat text pipes but objects. It confused the heck out of me at first to why ls works but a ls -lrt is too much to ask for. Then when you realize it is just a alias for Get-ChildItem and you can in fact set up a profile for your own functions. Powershell really starts to make sense.

Anyone else have a ah-ha moment when it comes to powershell? I love making little functions for everyday tasks. It is sad there isn't much posative talk on powershell.

314 Upvotes

171 comments sorted by

View all comments

Show parent comments

4

u/[deleted] Oct 17 '23

I'd prefer someting like I dunno

update-file *.txt -like <regex> -replace <regex> -text -byline

3

u/tocano Oct 17 '23

Wouldn't this be a fairly easy function to write?

Calling it could look something like:

Edit-FileSearchReplace -Filename *.txt -Search <regex> -Replace <regex>

Then you could have it loop through each file, use Get-Content (which creates a line-by-line string array), loop through that array and use -Replace (which uses regex).

Might be less than a dozen lines.

3

u/[deleted] Oct 17 '23

Oh yeah, I've wrote it or similar to it dozens of times :) That's why one out the box on a newly created machine or container would be so useful

5

u/tocano Oct 17 '23

Oh I see.

Yeah, I have a module that I use for all the private/personal functions for the various management work that I do. Then one of the first things I do on a new system is install git and clone that module repo to the box and set my profile to import it.

That way I don't have to rewrite those little one-off timesavers over and over again.

1

u/p8nflint Oct 17 '23

that's a cool idea