Don't do that, do this instead: PowerShell worst practices and how to solve them by Chris Gardner

  Рет қаралды 26,573

PowerShell.org

PowerShell.org

Күн бұрын

Пікірлер: 25
@TheStevenWhiting
@TheStevenWhiting 2 жыл бұрын
5:17 Aliases, that's what was doing my head in. Still learning, slowly and the amount of people that release their code with aliases is super annoying. I spend after the time working out what they mean. One script I wrote, as I know I'll forget, I even commented what ever single line was doing to make it even more readable. Obviously I know that's not possible for large scripts but still useful for me.
@krwhynot
@krwhynot 3 жыл бұрын
Thank you for this video, I have been using these "proper" Powershell grammar tips to my current scripts and it is helping clean them up. Thanks again!
@tonyme7426
@tonyme7426 Жыл бұрын
Got to love the question on camel case as that is the biggest discussion we have on projects with external developers. Naming conventions.
@HarmonicaMustang
@HarmonicaMustang 8 ай бұрын
Glad to see I follow most of these practices already, though I didn't know about the $array += optimisation, I went back to my old scripts and modified them, they run much better now.
@PhrontDoor
@PhrontDoor Жыл бұрын
I half agree with the hungarian notation one (around 14:20ish). Sure you can put other things in the $strName than a string. But if the programmer made it an strName then he likely intends for you to keep it a string so if you change it to an array, you'll break stuff done later on.
@daviddow5591
@daviddow5591 5 жыл бұрын
For more clarification on the memory usage of the array += thing: arrays are fixed sized collections of a single type. Assume you have an array (let's call it A) with 100 integers. If you want to add another integer to it (lets call this i), then the computer needs to allocate a new chunk of memory (let's call this array B) with enough space for 101 integers, copy A over to B, and then tack on i. So, if you do something like: $array = @(); 1..100 | foreach-object { $array += $_ } then you're asking the computer to allocate new memory 100 times. It isn't bad for small chunks of data, but adding data to the ends of lists is much more performant. If you want to run a head to head comparison, here's a piece of powershell code you can run (tested on v6): $range = 1..1000; $IntList=[System.Collections.Generic.List[int]]::new(); $IntArray = @(); write-output "List method(ms): $((measure-command -expression { $range | %{ $IntList.Add($_)}}).TotalMilliseconds)"; write-output "Array method(ms): $((measure-command -expression {$range | % {$IntArray += $_}}).TotalMilliseconds)"
@daviddow5591
@daviddow5591 5 жыл бұрын
Also, don't write code in scripts like the spaghetti I just wrote lol
@Chad-Skillable
@Chad-Skillable 11 ай бұрын
Chris talks about this at 22:12
@RPG_ash
@RPG_ash Жыл бұрын
Anybody know what the talk/video was about his comment at the end by a guy called Mike and WFP? I'd like to watch that.
@MuhammadBerki
@MuhammadBerki 2 жыл бұрын
Great session thanks 🙂👍
@fuleo
@fuleo 5 жыл бұрын
In vscode, there's "ms" command latency for every command he typed. How do I set that in vscode ?
@michaelo147
@michaelo147 5 жыл бұрын
Did you ever figure this out?
@citelao
@citelao 4 жыл бұрын
@@michaelo147 It's probably a custom prompt. If you grab and save the current time (globally) in the prompt, you can check that value the next time the prompt appears. If you subtract the two values, you get time elapsed. "Elapsed time PowerShell" and "custom PowerShell prompts" are good starting searches.
@michaelo147
@michaelo147 4 жыл бұрын
@@citelao I finally had some time for this and this was absolutely it. Thank you for teaching me something new.
@rpfrompr
@rpfrompr 3 жыл бұрын
@@citelao, could you explain? Was that added to him PS prompt?
@TheStevenWhiting
@TheStevenWhiting 2 жыл бұрын
@@rpfrompr As mentioned it appears to be related to the Prompt function. Where you can set what the prompt looks like. No clue on the code to make it display the elapsed time though. Someone has probably written a script for it somewhere.
@Our1stPlanet
@Our1stPlanet 3 жыл бұрын
All good stuff. Any chance of getting the source code on Github ?
@BrianLalonde
@BrianLalonde 5 жыл бұрын
Is "Select-Object" more readable than "select"? I don't think maximizing syntax increases readability. Zero aliases or positional params improves approachability for neophytes, but it's obscuring noise to anyone with experience trying to see the big picture.
@daviddow5591
@daviddow5591 5 жыл бұрын
Well, aliases are good for shorthand at the terminal too, but with powershell core, it looks like aliases are going to be going away to some extent
@gareginasatryan6761
@gareginasatryan6761 4 жыл бұрын
I agree. In a copy command it’s pretty obvious what the positional parameters are. copy was probably one of my first commands when I was around 13.
@-dash
@-dash 2 жыл бұрын
I think the idea is if you adhere to the schema, there's very little chance for ambiguity and almost certainly does anyone revisiting the code a favor. "Select", at a quick glance, could be referring to Select-String, Select-Object, Select-XML, etc.
@gorge5412
@gorge5412 4 жыл бұрын
Ouch. His . . . manner-of-speaking . . . is . . . very . . . difficult-to-understand. A few words gets spit out slowly; he stops, pausing, then races through the next fifteen words. Had to bail out after two minutes. IT TOTALLY DISTRACTS FROM CONCENTRATING ON MATERIAL.
@TheStevenWhiting
@TheStevenWhiting 2 жыл бұрын
American? He has an accent here in the UK, its probably that that's bothering you.
@geroffmilan3328
@geroffmilan3328 2 жыл бұрын
@@TheStevenWhiting sounded fine to me too.
@go-meditate
@go-meditate Жыл бұрын
I am a non-native english speaker and I understood everything perfectly fine.
How Strong Is Tape?
00:24
Stokes Twins
Рет қаралды 45 МЛН
The Best Band 😅 #toshleh #viralshort
00:11
Toshleh
Рет қаралды 21 МЛН
Basic To Boss: Customizing Your PowerShell Prompt by Thomas Rayner
46:03
PowerShell 2018: State of the Art by Jeffrey Snover
1:23:04
PowerShell.org
Рет қаралды 32 М.
PowerShell Functions
36:06
TechThoughts
Рет қаралды 44 М.
Writing Compiled PowerShell Cmdlets by Thomas Rayner
1:28:11
PowerShell.org
Рет қаралды 9 М.
Learn PowerShell: Episode 4, Types + Methods + Casting
28:55
Using Visual Studio Code as your Default PowerShell Editor
1:15:12
PowerShell.org
Рет қаралды 11 М.
PowerShell Errors and Exceptions Handling
27:49
TechThoughts
Рет қаралды 30 М.
Automating Active Directory Health Checks by Mike Kanakos
47:24
PowerShell.org
Рет қаралды 4,6 М.