r/PowerShell • • May 21 '17

OP PowerShell Training Course

Hey all,

So about 10 months back I asked for some help around creating a basic PowerShell training course for fellow engineers in an MSP. Most peeps there haven't taken the time to learn scripting by themselves, so the course had to break it down simply and teach them from the ground up.

Well... Thanks to all of your support, I've finally created the course! I've ran two training sessions so far, both lasting roughly 3 hours, and it seems to work!

I've had one engineer for whom it did just not click. I got to comparison operators and his brain just farted. As a teacher it felt awful not being able to make it click for it, but it has worked for about 30 other engineers.

I thought i'd post a link to the training here as a thank you to everyone who helped. It's on GitHub at the below URL:

https://github.com/Sudoblark/Powershell_Intro_Training.git

Happy scripting all!

106 Upvotes

20 comments sorted by

3

u/wonkifier May 21 '17

The place my folks ended up running into the most trouble was with loops.

They could describe them, if you gave them a simple one they could generally tell you what would happen, but they just could not build one on their own.

For something as simple as:

foreach ($user in $users) 
{
  write-output "working on $user"
  dosomething $user
}

They'd invariably write out

foreach ($user in $users) 
{
  write-output "working on $user"
}
dosomething $user

And wonder why the thing wasn't happening to all the users. There was just some sort of mental block we could never get through

2

u/Dogezon May 21 '17

Yeah my guys struggled with that at first. Once they got the concept of objects, arrays and enumeration they were alright.

I found that it helped to draw everything out on a whiteboard and visualise the enumeration process.

So I'd draw, for example, 5 bananas on a white board. A circle around of them to define the array and a square for my block of code. Then I’d be like “OK so this loop takes each banana out the array, applies this code, puts it back and then moves on to the next banana.” They struggled with what the first variable means so we named it a few things, like BigHairyBalls and ChocolateCake, to hit home the fact that it’s just the name given for each object.

Once you get past that mental block everything hits home! It’s just getting past it that’s tough.

3

u/wonkifier May 21 '17

Yeah, I think the problem on our side may be that I just can't get them to slow down enough to really think about things.

I suspect they're approaching it as just another set of procedures to memorize and apply magically, and this is time they're not spending on the tickets that are piling up for them.

Sadly that thinking is why those particular folks don't tend to be around the team anymore. We need more than instruction-following-button-pushers these days.

3

u/Dogezon May 21 '17

Support is such a fast paced environment that many people struggle to get out of the "break/fix" mentality. Especially where, in bigger companies at least, root cause analysis of stuff is dealt with by a different team than those fixing the incidents.

In MSPs the tickets are always piling up and peeps would rather close stuff and avoid their manager shouting at them than sit in a room for a few hours learning about scripting.

That think seems to be getting less and less, which is a good thing. You're right in that people need to think outside of just following instructions to fix something. Heck, why not write a button that'll fix it for you! Much more interesting. Also can't be done if engineers are rewarded based off of numbers on a spreadsheet. It's hugely beneficial to both know the scripting side of things and also have a solid operational overview of stuff. That's the most efficient type of engineer you can have imo.

1

u/[deleted] May 22 '17

BigHairyBalls and ChocolateCake, to hit home the fact that it’s just the name given for each object.

This was a major headache for me learning to code about 10 years ago. IT was horribly confusing the first time I encountered classes and they used the lower case name of the class for the instantiated object.

1

u/Dogezon May 23 '17

It's just one of those things that needs to click. I tend to find that if I'm enumerating through arrays then the array will be plural and the enumeration object singular. Probably a bad habit but it's clear and concise.

Classes are confusing to get your head round at first, I tend to use kettles as an example. Each kettle may have a custom paint job or something (instances) but the main things that make a kettle a Kettle (class) don't change. They all have a method for boiling water! Tried to use planes once but the guy was former RAF and started pointing out different plane specs 😂 Wasn't about to talk about parent classes etc so quickly skipped that.

1

u/mrw_im_on_reddit May 22 '17

Yeah, I think you just have to keep working with it. Years ago, I had the hardest time trying to work with hash tables and arrays (especially multidimensional) for the longest time. I don't know why. It just wouldn't click. Then one day, I was stuck on a script and the solution I needed (and described to myself) turned out to be a multidimensional array. After that, something clicked and I've never had a problem since. It's weird how the brain works.

1

u/Dogezon May 23 '17

Visualising multi-dimensional arrays really screwed my brain over. Learning Python I made a basic matrix which let you click on grids etc which then changed colour. It felt like someone was taking a saw to my skull but once it was all it place it just clicked and hey presto no problem. It's finding what makes it click for other people that makes teaching this stuff super fun and rewarding.

3

u/_Unas_ May 21 '17

This is when you talk about Scope. Just held a course and specifically mentioned scope in the terms of loops.

2

u/somewhat_pragmatic May 21 '17

That second non-working written way would mostly work in Ruby if the loop was written as a method with the method name "dosomething".

3

u/PhredFL May 21 '17

Sweet! I did something similar at my work but was aimed at intermediate level and how to do common admin-y tasks plus some pitfalls, protips etc. Ill check out your material.

Also if interested, i run our PS code review if you'd like a checklist

2

u/Dogezon May 21 '17

Awesomesauce. Sounds pretty cool, if you've got any of the material I'd be interested to have a read?

Certainly! I'd most definitely be interested in getting a checklist of your code review stuff! Always cool to see what other professionals are doing, every day is a school day after all.

2

u/[deleted] May 22 '17

I'd love to see that checklist.

I learned regular OOP long before I learned PS, so I'm always wondering if I should be writing my scripts in a more Powershelly way, if that makes any sense.

1

u/Lee_Dailey [grin] May 21 '17

howdy PhredFL,

could i talk you into posting your code review stuff to a new thread? it sounds like a really nifty area of discussion ... [grin]

take care,
lee

3

u/PhredFL May 21 '17

Yup! I was not able to find many basic review guidelines so we've evolved ours but id love to see what others can contribute. Will do tmro! My background is ex MS, worked w PS back in monad days and worked on the mess of script that manages SharePoint Online. Sooo i've seen a lot, lol.

2

u/Lee_Dailey [grin] May 22 '17

howdy PhredFL,

neato! i look forward to it ... and to the others who join in. perhaps you can drag /u/Dogezon into it. [grin]

take care,
lee

1

u/gonerlover May 21 '17

Can we have more information about the training and if it would happen again?

3

u/Dogezon May 21 '17

Sure! The readme on GitHub provides a brief overview but I'll go into some more detail here...

The course is run internally at the Company which I currently work at. The training covers some main topics, all backed up with practical examples, which cover some general coding basics as well as PowerShell basics. The course aims to give students a thorough understanding of the capabilities and limitations of PowerShell, eliminating the "fear" factor of a blue background and red text.

Ultimately, I wanted the course to give people the confidence to use PowerShell as a tool in their day-to-day sysadmin work. I was under no illusions that my line manager would want a desk of engineers automating tasks (he didn't) as only I was trusted to do that sort of stuff. If he did then I'd quite gladly follow this up with another, more technical course, covering concepts such as classes, advanced functions and modules.

When teaching the course it's important that people understand each concept before moving on to the next chapter. There's no point reviewing comparison operators if you don't understand what data types you're dealing with, there's no point reviewing control structures if you don't understand how the comparison operators work etc...

It's split into 8 sections (originally intended to be 9, but time constraints cut out the "idioms" part of the course) as follows:

  1. Background

  2. Primitive Data Types

  3. Comparison Operators

  4. Variables

  5. Control Structures

  6. Functions

  7. Common APIs

  8. Coding Standards

BACKGROUND:

This bit is mainly to give an overview of the context in which PowerShell exists. Outlining its capabilities and limitations. It is, first and foremost, an interpreted scripting language. You're not going to compile any runtime programs any time soon, although you can package PowerShell into other programs. For example, the Unity game engine can make use of PowerShell scripts for some of its logical functions.

PowerShell uses .NET. This allows you to hook in to some .NET functions and invoke COM objects. The example file for this section includes using a .NET form to produce a GUI with Groot as the background. The next section in the example then invokes a COM object (Excel) and inserts "I am groot" into the first three cells in the first row. It's a little silly, but then the first Guardians film came out around the time I finished this course so I thought that a topical example would break the ice. The PowerPoint also shows a classic .NET framework diagram. This isn't explained in too much detailed but just presented to students to give some context.

The bit that is REALLY important in this part of the course is the fact that PowerShell is object orientated. Explaining just what that means normally takes up a 3rd of the lesson in most instances. However, this point is important as the pipeline and control structures are dependant upon this fact. It's also important as once students understand this they then begin to understand the power that PowerShell has in manipulating and gathering large volumes of data. Once they learn about control structures they normally begin formulating their own ideas about how to automate their jobs, and one of the things I enjoy most about teaching this class is when people start telling me their ideas. Something clicks, they get it and suddenly the whole class erupts as ideas gets bounce around and suddenly everyone realises "holy shit I can save myself so much time if i automate all these manual and repetitive things i do. That'll allow me to spend more time doing all the cool stuff i enjoy about support like breaking DAGs or making a new dfs namespace for my porn and replicating it across 30 different file servers.".

This bit also explains some mundane stuff like what certain buttons in ISE do, the get-help cmdlet and the naming structure. The naming structure is the 2nd most important thing people need to learn. If they can understand how the language is structured - and understand that it's object orientated - they can make educated guesses how to do quite a lot else.

PRIMITIVE DATA TYPES

This bit just covers some basic data types, nothing too special. Integers, strings, booleans and arrays. Also teaches students how to typecast variables.

COMPARISON OPERATORS

This bit is where people starting either getting the hang of things or start struggling. It only covers 4 operators:

  • Greater Than

  • Less Than

  • Like

  • Equals

Practical examples are given for each operator. The thing that people tend to struggle with her is arrays. Comparison operators will return a boolean if the input is singular, but if the input is an array then it will return all true values. What catches people out is that if there are no matching true values then they expect it to return false as a boolean. WRONG! The operator will return all true values and if no item is true then it simply returns nothing. It literally returns nothing, not even a null. I've tested this as per below:

PS C:\WINDOWS\system32> $Test = 2,3,4 -gt 5

PS C:\WINDOWS\system32> $test

PS C:\WINDOWS\system32> $Test | gm gm : You must specify an object for the Get-Member cmdlet. At line:1 char:9

  • $Test | gm

  •     ~~
    • CategoryInfo : CloseError: (:) [Get-Member], InvalidOperationException

    • FullyQualifiedErrorId : NoObjectInGetMember,Microsoft.PowerShell.Commands.GetMemberCommand

The examples are run through individually with each member of the class. It is imperative that everyone understands how these operators work as they are essential to the control structures. It is also imperative that everyone understands control structures as this is where all the meaty stuff happens and you begin doing the cool bits and bobs. There's honestly no point moving on to the next chapter if students don't understand this part; they'll just get frustrated and annoyed at their lack of understanding. Make the comparison operators click first!

CONTROL STRUCTURES

This bit is the fun part, where people can start seeing practical applications for the knowledge that they are acquiring. It only covers the basics:

If If else While Foreach

Again, practical examples are given for each control structure. There's also a bad while loop example which will never close. When teaching the part about while loops I make sure to hammer home the point that you absolutely MUST provide a method for your while loop to close, otherwise it'll never end. Most people are fine with the first 3 structures but get hung up with the foreach loop. I always have a whiteboard handy and will run through the enumeration process step by step in order to explain the logic behind the structure.

Practical examples are given at the end of using DOT notation to access attributes of enumerating objects.

FUNCTIONS

This bit is only covered briefly. I'll explain the concept of a function and how useful they are. The general syntax of a function and a basic way of sticking in a parameter. More advanced topics, such as mandatory parameters and accepting pipeline input, are not covered.

COMMON APIs

This bit is only glanced over. No real explanation is given as to the example code. Rather, it is run and students are shown practical examples of APIs commonly used. The reason for Azure AD and Office 365 being chosen is just that it's mainly what 1st/2nd line will deal with, so it makes sense to show them how to hook in to it. At this point, the class will also be told about Microsoft modules for various common applications such as Active Directory. They'll also be told about third party modules, such as PowerCLI and backup exec's module (can't remember the name off the top of my head).

Students will be told that every Microsoft application is really just a fancy GUI which runs PowerShell commands in the backend. They'll also learn that there's a heck of a lot which PowerShell offers that isn't available in a GUI due to a lack of real estate (an interface with 20 buttons, a spinning hat and lasers isn't easy to navigate).

They'll also learn how to connect/disconnect PSSessions.

CODING STANDARDS

This bit uses my first every new user script (it's so cute and basic). Obviously, all the client sensitive information has been stripped out. The point is that, functionally, both the bad and good standard's are fine; both will perform the same function if run. The point is that the bad standard is an absolute mess. To quote a student in my last class: "There's no point in writing a script if you can't look back on it in a year's time and understand what's going on.". This section is used to aggressively recommend students to use comments, whitespace, indentation and CamelCasing.

I think that about covers it. Sorry if there's spelling mistakes or bad grammar; I'm on call today and am absolutely knackered! The course is extremely basic. The points covered could easily be stretched out to cover a week. I was given an hour by my line manager to each all of the above ("we can't have engineers off the desk for too long!") so I'm very much aware that it's not a complete guide. However, I've found that it's enough to cover the basics and spark enough interest in students to warrant self study. There are further reading links provided at the end of the course as well. The cheat sheet is not made by myself, i take absolutely no credit for it whatsoever. I do think that whoever did make it is extremely clever and that it's a great little reference sheet to provide to students at beginning of the class.

If I had the time I'd expand upon this course, finish every chapter with a test for students and extend it to quite a bit longer than 3 hours; possibly two or three days.

I hope that provides the information you require?

As for when it's happening again, I've only ever taught this as an internal course. I haven't really thought about teaching this externally, but if there's enough interest I don't see why not.

1

u/gonerlover May 21 '17

This is probably the most thought out course for beginners that I would have loved to see take. Considering I am a noobie I would have very much liked to srr/take this

0

u/[deleted] May 21 '17

[deleted]

1

u/Dogezon May 23 '17

I wouldn't say it's too much. It's just finding the equipment and time. My current company probably wouldn't let me record it. But if I could find enough people near me and the equipment to record then I certainly don't see why not!