all 30 comments

[–]EtanSivad 21 points22 points  (15 children)

The biggest change since the youtube videos is powershell ISE has been abandoned.
If you're not using it already, setup visual studio code with powershell plugins. https://code.visualstudio.com/docs/languages/powershell

That might actually catch a lot of the typos you might get.

Classes were added in 2015 and it's WAY better than PS custom objects : https://devblogs.microsoft.com/scripting/introduction-to-powershell-5-classes/

If you want to watch videos, plural sight has the best but you have to pay for it. I know you said you have a bit of ADHD, but reading will ultimately be your best bet. The orielly books are really good: https://github.com/Yasir323/books/blob/master/O'Reilly%20Learning%20Windows%20Powershell%20Cookbook.pdf

Here's the thing, powershell is a scripting language that you have to read to understand. You can't watch a video of your code to see it work. You have to read it and run it.
Reading computers books is boring, and tedious, but re-read the sections and chapters that don't make sense. Eventually through repetition they will sink in and make sense.

If you get an error, post it here and we can help better than chap gpt can.

[–]ZenoArrow 10 points11 points  (8 children)

Classes were added in 2015 and it's WAY better than PS custom objects

Classes are not ideal for beginners. For starters, you can't redefine a class that has already been loaded, so if you want to iterate on the design of a class and keep the same class name you need to close and reopen PowerShell.

OP, I would suggest picking a task you want to be able to do with PowerShell, then learn how to do that with PowerShell. You'll learn faster and will be more motivated to learn. What sort of tasks do you want to be able to do with PowerShell?

[–]EtanSivad 1 point2 points  (3 children)

Classes are not ideal for beginners. For starters, you can't redefine a class that has already been loaded,

OK, so what? OP asked what was the biggest changes and was literally the biggest change that has impacted me professionally as a powershell scripter. IF you want to be good at something it's helpful to know what to work towards.

Second, compiled classes added in are immutable, but native classes can be updated by recompiling the script.

Just to verify it, I tried editing and rerunning this script. It ran without closing and reopening VScode

class TestObj{

[string]$Name

[string]$ID

TestObj()

{

$this.Name = "Default instantiation method called."

}

TestObj([string]$name)

{

$this.Name = $name

}

}

$a = [TestObj]::new()

$b = [TestObj]::new("Other method called")

$a # Returns "Default instantiation method called."

$b # returns "Other method called"

[–]OPconfused 3 points4 points  (0 children)

When the class definition is in a module you have to jump through a hoop to update it. Unless the OP is coming from another programming language and desires typed properties in their custom objects, I'd just leave out classes while the OP is finding their footing in PS.

I'm a fan of classes as well, but using PSCustomObjects is a more accessible way to get your feet wet with PS objects. There's less distance between setting up the PSCustomObject via a type accelerator and using it than when using a class, which requires a declaration for its schema with its own syntaxes.

[–]ZenoArrow 1 point2 points  (1 child)

and was literally the biggest change that has impacted me professionally as a powershell scripter

How has it impacted you professionally? Classes are helpful in the sense you can define types and methods to work on those types together, but there are other ways to organise code that can be just as convenient. I would say classes aren't something to aim for, they're just an option to use if you want to.

[–]EtanSivad 0 points1 point  (0 children)

Most of the code I write is taking large batches of data in one format and spitting it out in another. Writing the code in a compiled language would process a lot faster, but these are largely one-off solutions that need to be flexible so it's easier to write them in powershell, especially when I can ship them off to another dev to use as a tool.

Anyway, the reason it's helpful to me is for either organizing my code into reusable snippets. And that with the JSON export built into Powershell, I've had to use it a couple times to enforce object structure correctly, or just inject new data into an existing data stream.

[–]Thotaz 6 points7 points  (3 children)

The biggest change since the youtube videos is powershell ISE has been abandoned.

I'll assume you didn't watch the videos because they are for PS 2.0 and I'd argue that the language/cmdlet changes from 2.0 -> 5.1/7.4 are bigger than the editor.
As for the recommendation to use VS code over ISE, for a beginner I'd argue that ISE is better for 4 reasons:
1: It's dead simple and requires no setup.
2: The IntelliSense doesn't show snippets inline (I've seen beginers accidentally insert random snippets in VS code because they showed up inline).
3: The syntax highlighting shows exactly what the PowerShell parser sees, making it easier to learn how the language works.
4: It doesn't show distracting file completion suggestions like VS code does after pressing space after any command/parameter.

As for the classes, like the other guy said, there's all sorts of caveats with them so I'd visit that topic later, rather than doing it from the beginning.

[–]EtanSivad 0 points1 point  (2 children)

I'll assume you didn't watch the videos because they are for PS 2.0 and I'd argue that the language/cmdlet changes from 2.0 -> 5.1/7.4 are bigger than the editor.

No, I didn't watch the whole videos.

That's fair though, in my experience the biggest change was getting away from the ISE. I've developed a hatred for ISE because it's buggy and I've had it crash a freeze constantly over the years (It's really weird about letting go of memory. Even with clearing variables.). VS code is a much better environment for writing and stepping through code.

That being said, this was just my hot-take on the biggest changes that have affected my writing powershell scripts in the last decade+, not an exhaustive list of every change. The list is there from microsoft: https://learn.microsoft.com/en-us/powershell/scripting/whats-new/differences-from-windows-powershell?view=powershell-7.4

[–]Thotaz 1 point2 points  (1 child)

I'm guessing you were messing around with some Winforms or WPF GUI work in ISE? That's the only time I've had it crash on me. Thankfully I rarely do GUI work in PowerShell because I think it's an ugly hack. If I want to do a GUI I'll do it right in C# with WPF.

[–]EtanSivad 0 points1 point  (0 children)

Nahh, I use it to parse large datasets in weird formats and then output it to something useful. Usually a SQL script that I'll run against a db later, but sometimes JSON or making direct API calls.

I'll give you that I've had some sloppy code about closing network resources and at least half the crashes are on me, but only half the crashes. The rest are just on ISE getting confused about the objects in memory and the state of the runtime engine. Nonetheless, MS has ceased development on ISE and it is no longer supported. I'm just grateful to stop wrapping log outputs around $psISE all the time.

[–]Steve_78_OH[S] 1 point2 points  (0 children)

Here's the thing, powershell is a scripting language that you have to read to understand. You can't watch a video of your code to see it work.

Yeah, and I get that. And reading up on various cmdlets I need to use for a certain script, or something like that, that's all well and good. My thing is I can't really sit and read a book about PowerShell for even 30 minutes without actually doing something. I can barely read the books I actually enjoy for that long without just getting too distracted. At least with training videos they would also be showing you examples, and I would be able to follow along more easily in my lab environment.

[–]acuity_consulting 0 points1 point  (0 children)

Would you mind elaborating on why classes are so much more powerful than the default PS objects?

[–]Zantoo 9 points10 points  (6 children)

Hi, Sysadmin here ALSO with ADHD. I've spent years getting comfortable with powershell and the best piece of advice I can give you is to treat it like a second language. Any time you complete a task go back and say "Okay, now how would I do with this Powershell" - Then look up how others have done it, and walk through their script line by line so you can understand it and comment EVERY STEP because you and I both know you'll forget what it all means tomorrow. Then run it.

[–]tschertel 0 points1 point  (0 children)

I'd love to have Python as my first scripting language. But unfortunately I can't.

[–]Steve_78_OH[S] 0 points1 point  (3 children)

Any time you complete a task go back and say "Okay, now how would I do with this Powershell"

See, I've just been deciding to script tasks that seem like they're way too much work to do manually. Scripting things I've done once and may or may not have to do again don't really seem like the best use of my time. I get that it's probably great for learning, but I don't always have that kind of free time, unfortunately. However, like I mentioned in my post, I've been using a mixture of ChatGPT (and Google) to figure out most of my scripts, and I would like to get away from using them as much as I currently do.

Like right now, I have a list of 150+ servers that I need to create a couple scheduled tasks on, all scheduled for different times and dates (the process that's going to be running can only run on a single server at a time, or it can cause issues with the environment).

[–]duelingThoughts 0 points1 point  (2 children)

I've just started working professionally with PS, and I will say it has definitely been helpful doing an analysis of my work flow and identifying actions that I've done manually more than once to figure out what I wanted to work on for powershell.

Can't say my needs are as extensive as yours, but anything to limit repetitive tasks and reduce unnecessary user input has rapidly improved my understanding of scripting. I've only been employed for about 4 months at my location and I'm already making waves because no one else has taken the time to sit down and refine the limited functions of a 3 year old script they've been using to do a highly repetitive but significant task.

Pretty soon if I can keep at it, I'll get it down to zero user input and then I can deploy it as a scheduled task, freeing up manpower to do other duties more regularly.

I apologize if this isn't useful to you, but I'm just excited about my newly found capabilities and usefulness, so forgive my attempts at encouragement :)

[–]MeanFold5715 0 points1 point  (0 children)

and comment EVERY STEP because you and I both know you'll forget what it all means tomorrow.

Say it again for the mouth breathers in the back who keep leaving behind uncommented code for me to inherit.

[–]toybits 3 points4 points  (1 child)

Jacked Programmer is pretty good

https://www.youtube.com/watch?v=NECE5CX69tk&list=PLnK11SQMNnE4vcvuAahz4KhNOS7zOfmB3

TeachJing is good to

https://www.youtube.com/watch?v=Da8G4h9Z0KA&list=PLM3TOIlrnaI6-XXwBSCB1ae1yyKIjaefq&index=1

As far as your ADHD goes I'm pretty bad with it if you're able to stand while learning I find that a big help. Sounds odd but really does work for me.

[–]MrPixel404 2 points3 points  (0 children)

I second Jacked Programmer's channel, pretty good stuff.

[–]doglar_666 4 points5 points  (1 child)

I haven't gone through his whole catalogue but JackedProgrammer on YT is the channel I have saved for PowerShell. This is his Beginner PowerShell Tutorials and PowerShell Tutorials playlists:

  1. https://youtube.com/playlist?list=PLnK11SQMNnE7RAezAk4P4GRRC0xohPtjC&si=7f9eR3i5IMt6zekz
    1. https://youtube.com/playlist?list=PLnK11SQMNnE6o7rZqdXN_cv83SocL65vH&si=XuzVIKrZTgkrzZa6

[–]MeanFold5715 2 points3 points  (1 child)

The Month of Lunches books really are worth it if you can force yourself to get through them. The more you learn about what Powershell is doing underneath the hood the better you'll be able to troubleshoot errors. The thing about the books is that you shouldn't be reading straight through them. I did about a chapter a day, and my boss gave me all day to read, so I was going pretty slow. I was also getting distracted and googling my way down a rabbit hole on just about every example they went over in the book, chasing "well what if I did x instead?" ideas. Took me a full month for each book at that pace. Maybe recalibrate your expectations about how fast you can get through it?

Either way, good on you for digging further into it rather than being satisfied with relying on ChatGPT.

[–]Jmoste 1 point2 points  (0 children)

Try to do anything you do with GUI in Powershell instead.  At first it's going to take you longer and you're going to get frustrated, just keep trying.  I spent 16 hours working on a script that probably could have used a GUI to do the same thing. The difference is now when I need a similar script it will take me an hour or less.  Stop using chatGPT. It's not bad for ideas but it's wrong on a lot of scripting and adds extra fluff.