title: Put the knife down and take a green herb, dude. |
descrip: One feller's views on the state of everyday computer science & its application (and now, OTHER STUFF) who isn't rich enough to shell out for www.myfreakinfirst-andlast-name.com Using 89% of the same design the blog had in 2001. |
FOR ENTERTAINMENT PURPOSES ONLY!!!
Back-up your data and, when you bike, always wear white. As an Amazon Associate, I earn from qualifying purchases. Affiliate links in green. |
|
x
MarkUpDown is the best Markdown editor for professionals on Windows 10. It includes two-pane live preview, in-app uploads to imgur for image hosting, and MultiMarkdown table support. Features you won't find anywhere else include...
You've wasted more than $15 of your time looking for a great Markdown editor. Stop looking. MarkUpDown is the app you're looking for. Learn more or head over to the 'Store now! |
|
Wednesday, November 03, 2021 | |
I've been c-sharping a long time. It's been a while since I've PowerShelled. They're very close, but not quite the same. Here are just a few of the things I needed to relearn to accomplish what I was working on most recently. Loading modulesFrom "How do I force powershell to reload a custom module?":
And to grab it from within a ps1 file:
Function parametersFrom "How to get all arguments passed to function (vs. optional only $args)":
Passing parameters to functions, including "switch" parameters:
Using positional parameters and pipeline values:
If you want the graduate school version, here's some info on parameter sets. Backticks and line breaksThough .NET style
Instead you have to
Also note the backticks that allow you to throw a single command over several lines. Here's a great treatment of backtick use:, though let's spoil the ending and admit now they do a great job explaining why you shouldn't use it to have a line of code span several lines (I feel like the author must have one of those double-wide monitors or uses word wrap): From blogspot.com:
That last line is hilarious, btw, and there's an even better argument against backtick use just a little further down:
Well done. They even use "its" correctly in the post. Impressive. I mean, this is part of the reason I set my text editors (hat can) to delete all end of line whitespace -- I'm now trying to think of a use case where you'd want EOL whitespace -- and I don't agree that it makes code harder to maintain. Line breaks can make code much more easy to read and digest when you're reviewing existing code. But all in all this is an excellent post on backticks and PowerShell. Regardless, the point here is that backticks can't be used to escape newlines in Hashtables and [some about] custom objectsYes, you can add properties to hashtables like a variant/dynamic type, similar to JavaScript. From microsoft.com:
The easiest way to add custom objects (similar to .NET anonymous objects) might be this:
But if you wanted to see all the ways to create a new object throughout PowerShell history (archive link:
Examples at that page. From microsoft.com:
Also note examples for saving to/from JSON:
That's pretty clean. Ok, here's an important edit: splatting, which is better than backticks for breaking up function calls with too many parameters to view cleanly.
The more I read that giant blog post (mentioned above, as well), the more I'm buying in on his best pratices. Labels: noteToSelf, powershell posted by ruffin at 11/03/2021 01:22:00 PM |
|
| |
All posts can be accessed here: Just the last year o' posts: |
||||||||||||||||||||||
|