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

View all comments

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