1
00:00:01,140 --> 00:00:05,040
The first term I need to define is cmdlet.

2
00:00:05,040 --> 00:00:07,340
This is the basic PowerShell command.

3
00:00:07,340 --> 00:00:11,020
Think of the name as meaning little command, cmdlet.

4
00:00:11,020 --> 00:00:14,810
Cmdlets are written in a .NET language and compiled.

5
00:00:14,810 --> 00:00:15,070
Now,

6
00:00:15,070 --> 00:00:18,370
those details don't really matter to you other than realizing

7
00:00:18,370 --> 00:00:20,650
that these are essentially binary commands,

8
00:00:20,650 --> 00:00:22,940
so you can't see the source code.

9
00:00:22,940 --> 00:00:27,510
The most important aspect of a cmdlet is that it does one thing and

10
00:00:27,510 --> 00:00:30,740
writes one type of object to the PowerShell pipeline.

11
00:00:30,740 --> 00:00:30,810
Now,

12
00:00:30,810 --> 00:00:33,910
this is very similar to the Linux model where command line

13
00:00:33,910 --> 00:00:37,240
programs like grep and sed only do one thing,

14
00:00:37,240 --> 00:00:41,640
and then you join them together to make a single command statement.

15
00:00:41,640 --> 00:00:44,740
Now we don't have monolithic commands in PowerShell.

16
00:00:44,740 --> 00:00:48,740
We have commands that do specific things like get a service or stop a

17
00:00:48,740 --> 00:00:52,340
process or create a new Active Directory user account.

18
00:00:52,340 --> 00:00:55,640
A function isn't that much different than a cmdlet.

19
00:00:55,640 --> 00:00:58,210
In fact, it behaves just like a cmdlet.

20
00:00:58,210 --> 00:01:01,840
You, when you use it, really can't tell the difference.

21
00:01:01,840 --> 00:01:04,870
But one big difference is that functions are almost always

22
00:01:04,870 --> 00:01:07,290
written in PowerShell scripting language.

23
00:01:07,290 --> 00:01:09,090
This means you can look at the source code.

24
00:01:09,090 --> 00:01:11,240
Now you typically wouldn't change it,

25
00:01:11,240 --> 00:01:15,070
but because functions are typically a type of PowerShell script,

26
00:01:15,070 --> 00:01:17,950
you will eventually learn how to write your own.

27
00:01:17,950 --> 00:01:20,260
And functions, like cmdlets,

28
00:01:20,260 --> 00:01:25,340
are designed to do one thing and write one type of object to the pipeline.

29
00:01:25,340 --> 00:01:26,640
Yes, there are always exceptions,

30
00:01:26,640 --> 00:01:29,540
but that should be the model that you will follow.

31
00:01:29,540 --> 00:01:33,030
You'll also encounter the term script in PowerShell.

32
00:01:33,030 --> 00:01:38,300
Now scripting is the journal process of creating these types of commands.

33
00:01:38,300 --> 00:01:43,640
A PowerShell script is a text file with a PS1 file extension.

34
00:01:43,640 --> 00:01:46,840
The commands in the file are executed sequentially,

35
00:01:46,840 --> 00:01:50,270
just as if you had typed them manually at a PowerShell prompt.

36
00:01:50,270 --> 00:01:54,340
You can think of a PowerShell script as a fancy type of batch file.

37
00:01:54,340 --> 00:01:57,090
We use PowerShell scripts to define our functions,

38
00:01:57,090 --> 00:02:00,640
but more often we use scripts to run cmdlets and functions in

39
00:02:00,640 --> 00:02:03,240
some sort of structured or planned order.

40
00:02:03,240 --> 00:02:08,040
A good way to think of PowerShell scripts is as a controller or orchestrator.

41
00:02:08,040 --> 00:02:11,640
You can use a PowerShell script to automate tasks and steps.

42
00:02:11,640 --> 00:02:15,000
I often think of them as canned or recorded PowerShell sessions,

43
00:02:15,000 --> 00:02:18,250
so instead of interactively running a series of commands,

44
00:02:18,250 --> 00:02:22,300
I can put them in a PS1 file and execute the script.

45
00:02:22,300 --> 00:02:26,640
PowerShell scripts have a bit more flexibility and can do more than one thing,

46
00:02:26,640 --> 00:02:29,140
but you don't want to get too monolithic.

47
00:02:29,140 --> 00:02:32,940
There's plenty of PowerShell scripting content in the Pluralsight catalog.

48
00:02:32,940 --> 00:02:35,730
Technically, there is one more type of PowerShell command,

49
00:02:35,730 --> 00:02:41,220
and that is an alias. Although in reality an aliases just an

50
00:02:41,220 --> 00:02:43,730
alternate name for a PowerShell command,

51
00:02:43,730 --> 00:02:47,540
such as a cmdlet, function or script,

52
00:02:47,540 --> 00:02:50,620
they're often shorter and sometimes easier to use.

53
00:02:50,620 --> 00:02:53,140
So instead of typing the command Get‑Process,

54
00:02:53,140 --> 00:02:56,910
you could type a shorter alias like ps. In fact,

55
00:02:56,910 --> 00:02:59,440
one of the reasons we had aliases were to provide

56
00:02:59,440 --> 00:03:02,490
transitions from other shells and platforms.

57
00:03:02,490 --> 00:03:04,830
If you need to list files in a folder by don't know

58
00:03:04,830 --> 00:03:07,140
the actual PowerShell command yet, which,

59
00:03:07,140 --> 00:03:12,440
by the way, is Get‑ChildItem, you can use an alias like dir or ls.

60
00:03:12,440 --> 00:03:14,740
Although be aware that on Linux systems,

61
00:03:14,740 --> 00:03:17,770
many of the PowerShell aliases have been removed to avoid

62
00:03:17,770 --> 00:03:22,030
conflicting with the real native commands like ls or ps.

63
00:03:22,030 --> 00:03:24,870
The last definition I have for you is parameter.

64
00:03:24,870 --> 00:03:28,430
Now you'll hear this term a lot in PowerShell. This is something

65
00:03:28,430 --> 00:03:31,630
that applies to cmdlets, functions, and scripts.

66
00:03:31,630 --> 00:03:35,640
A parameter provides a way to customize the behavior of the command,

67
00:03:35,640 --> 00:03:39,480
such as specifying a certain path or group of services.

68
00:03:39,480 --> 00:03:41,830
Command line tools have always had parameters,

69
00:03:41,830 --> 00:03:44,450
sometimes they are referred to as switches.

70
00:03:44,450 --> 00:03:47,500
But don't hold on to that term as switch. In PowerShell,

71
00:03:47,500 --> 00:03:51,440
it means something entirely different, which you'll eventually learn.

72
00:03:51,440 --> 00:03:53,980
The important thing for you to know right now is that

73
00:03:53,980 --> 00:03:56,130
some parameters are positional,

74
00:03:56,130 --> 00:04:00,690
meaning you only have to type the value like the name of a service.

75
00:04:00,690 --> 00:04:01,660
Otherwise,

76
00:04:01,660 --> 00:04:06,340
all parameters in PowerShell follow a standard convention of a dash,

77
00:04:06,340 --> 00:04:09,870
then the parameter name, a space, and then the value.

78
00:04:09,870 --> 00:04:13,560
If you need to pass multiple values, like a group of computer names,

79
00:04:13,560 --> 00:04:17,240
those are separated by commas. As you work with PowerShell,

80
00:04:17,240 --> 00:04:21,100
you'll also see the parameter names are also kind of standardized.

81
00:04:21,100 --> 00:04:24,350
If you need to specify the parameter and pass the name of a computer,

82
00:04:24,350 --> 00:04:27,140
it's almost always going to be computer name.

83
00:04:27,140 --> 00:04:34,000
These standards make PowerShell commands easy to learn and use because you don't have to guess at they syntax.

