en-us/about_PSTeachingTools.help.txt

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
TOPIC
    about_psteachingtools
 
SHORT DESCRIPTION
    The PSTeachingTools module is designed to offer a set of PowerShell commands
    that can be used to demonstrate and teach PowerShell fundamentals.
 
LONG DESCRIPTION
    Very often, PowerShell teachers use out-of-the-box cmdlets like Get-Process
    and Get-Service to demonstrate concepts and techniques. However, sometimes
    the commands themselves or their output might be distracting. This module
    contains a set of commands based on a more neutral and non-technical noun,
    a vegetable.
 
    The *-Vegetable commands are designed to be combined in pipelined
    expressions like regular PowerShell commands. These demonstration commands
    also write objects to the pipeline. The custom objects have a corresponding
    custom format.ps1xml file, which displays results in a formatted table. Many
    PowerShell commands, like Get-Service use this same technique. The concept
    behind these demonstration commands is that once students see how vegetable
    objects can be used, consumed and manipulated in PowerShell, the same
    concepts and techniques can be applied to service, process, or any other
    object type in PowerShell.
 
    For advanced classes, you can use the module files themselves to teach
    concepts as module development, advanced functions, PowerShell classes,
    working with JSON and CSV files, and format.ps1xml files.
 
EXAMPLES
    The Get-Vegetable command is designed to demonstrate how PowerShell works
    and how you can work with PowerShell. Once the student understands how this
    command works, they should be able to apply the concepts to any other
    command.
 
    PS C:\> Get-Vegetable
 
    UPC Count Name State Color
    --- ----- ---- ----- -----
    4078 12 corn Roasted yellow
    4064 4 tomato Raw red
    4062 11 cucumber Raw green
    4562 10 carrot Raw orange
    4089 13 radish Raw red
    4674 14 peas Steamed green
    4811 12 turnip Boiled purple
    4725 18 russet potato Fried brown
    4060 15 broccoli Steamed green
    4067 7 zucchini Raw green
    4090 4 spinach Raw green
    4572 7 cauliflower Steamed white
    3125 17 habanero pepper Raw orange
    4677 16 Anaheim pepper Raw green
    4088 19 red bell pepper Sauteed red
    4081 6 eggplant Fried purple
    4604 2 endive Raw green
 
    When you import the module, a set of vegetables is generated from a JSON
    file.
 
    PS C:\> Get-Vegetable corn | Get-Member
 
       TypeName: PSTeachingTools.PSVegetable
 
    Name MemberType Definition
    ---- ---------- ----------
    Equals Method bool Equals(System.Object obj)
    GetHashCode Method int GetHashCode()
    GetType Method type GetType()
    Peel Method void Peel()
    Prepare Method void Prepare(PSTeachingTools.VegStatus State)
    ToString Method string ToString()
    Color Property PSTeachingTools.VegColor Color {get;}
    CookedState Property PSTeachingTools.VegStatus CookedState {get;set;}
    Count Property int Count {get;set;}
    IsPeeled Property bool IsPeeled {get;set;}
    IsRoot Property bool IsRoot {get;}
    Name Property string Name {get;}
    UPC Property int UPC {get;}
 
    The default display uses the format.ps1xml file which does NOT reflect the
    complete object. This is typical PowerShell behavior. Get-Process and
    Process objects are a good example.
 
    Here are some other ways you could use the command to demonstrate common
    PowerShell techniques and concepts:
 
    PS C:\> Get-Vegetable | Group-Object -Property Color
 
    Count Name Group
    ----- ---- -----
        8 green {PSTeachingTools.PSVegetable, PSTeachingToo...
        3 red {PSTeachingTools.PSVegetable, PSTeachingToo...
        1 white {PSTeachingTools.PSVegetable}
        1 yellow {PSTeachingTools.PSVegetable}
        2 orange {PSTeachingTools.PSVegetable, PSTeachingToo...
        2 purple {PSTeachingTools.PSVegetable, PSTeachingToo...
        1 brown {PSTeachingTools.PSVegetable}
 
    PS C:\> Get-Vegetable -RootOnly | Measure-Object -Property count -sum
 
    Count : 4
    Average :
    Sum : 53
    Maximum :
    Minimum :
    StandardDeviation :
    Property : Count
 
    Read full help and examples for New-Vegetable and Set-Vegetable.
 
PSVegetable Class
    The object class and its enumerations are now exposed in PowerShell.
 
    PS C:\> [enum]::GetNames([PSTeachingTools.VegColor])
    green
    red
    white
    yellow
    orange
    purple
    brown
 
    PS C:\> [enum]::GetNames([PSTeachingTools.VegStatus])
    Raw
    Boiled
    Steamed
    Sauteed
    Fried
    Baked
    Roasted
    Grilled
 
    PS C:\> [PSTeachingTools.PSVegetable]::new.OverloadDefinitions
    PSTeachingTools.PSVegetable new(string VegetableName, bool Root, PSTeachingTools.VegColor VegetableColor, int UPCCode)
 
SEE ALSO
    https://aka.ms/powershell
    https://jdhitsolutions.com/blog/essential-powershell-resources/
    https://jdhitsolutions.com/blog/powershell-tips-tricks-and-advice/
 
KEYWORDS
    - teaching
    - demo