11# Requires -Module PSKoans
2- [Koan (201 )]
2+ [Koan (Position = 201 )]
33param ()
44<#
5- Get- Help
5+ Help & Discovery
66
7- Get-Help is a built-in PowerShell cmdlet that is used to retrieve help data for
8- cmdlets and functions. It contains usage examples, parameter information,
9- and a significant amount of otherwise difficult to discover tidbits .
7+ PowerShell's help and discovery systems are a key component to its ecosystem. A great
8+ many things can be learned simply by knowing where to look and which few cmdlets to
9+ use in order to find what you're looking for .
1010
11- Get-Member
12-
13- Get-Member is another built-in cmdlet that is invaluable in retrieving
14- information about any object in PowerShell. It can be used to inspect the type
15- name of an object, as well as all available methods and properties that can be
16- accessed for that object.
17-
18- These cmdlets are quintessential discovery tools, and regular use of them will
19- vastly expedite any unfamiliar task in PowerShell. Combined with well-placed
20- Google searches, it is possible to learn a significant amount about native
21- PowerShell cmdlets and functions, and more advanced .NET classes, and methods.
11+ Discovery cmdlets are quintessential learning tools, and regular use of them will
12+ vastly expedite any unfamiliar task in PowerShell. Combined with targeted online
13+ searches, it is straightforward to learn a significant amount about native PowerShell
14+ cmdlets and functions, as well as more advanced .NET classes, and methods.
2215#>
23-
2416Describe ' Get-Help' {
17+ <#
18+ Get-Help
2519
20+ Get-Help is a built-in PowerShell cmdlet that is used to retrieve help data for
21+ cmdlets and functions. It contains usage examples, parameter information, and
22+ a significant amount of otherwise difficult to discover tidbits.
23+ #>
2624 Context ' shows help information about cmdlets' {
2725 # Try calling 'Get-Help Get-Help' in a console to see the built in help available
2826 # for the help command.
@@ -55,11 +53,27 @@ Describe 'Get-Help' {
5553 $ParameterInfo.PipelineInput | Should - Be __
5654 }
5755 # Remember: if 'Get-Help Cmdlet-Name' doesn't show you all you need, try -Full. You'll need it.
56+
57+ It ' can search for commands by parameter names' {
58+ $RemoteCommands = Get-Help - Name * - Parameter ComputerName |
59+ Select-Object - ExpandProperty Name
60+
61+ $RemoteCommands.Count | Should - Be __
62+
63+ $RemoteCommands [4 ] | Should - Be __
64+ }
5865 }
5966}
6067
6168Describe ' Get-Member' {
62-
69+ <#
70+ Get-Member
71+
72+ Get-Member is another built-in cmdlet that is invaluable in retrieving
73+ information about any object in PowerShell. It can be used to inspect the type
74+ name of an object, as well as all available methods and properties that can be
75+ accessed for that object.
76+ #>
6377 Context ' Members and methods of objects' {
6478
6579 It ' can help you find useful properties' {
@@ -117,8 +131,8 @@ Describe 'Get-Member' {
117131 Context ' Members of objects returned from cmdlets' {
118132
119133 It ' can help you discover information about unfamiliar objects' {
120- # Cmdlets also return objects! This cmdlet creates an empty .tmp file in a random location,
121- # and returns the object representation of this file.
134+ # Cmdlets also return objects! This cmdlet creates an empty .tmp file in a random
135+ # location, and returns the object representing this file.
122136 $TempFile = New-TemporaryFile
123137 Test-Path - Path $TempFile.FullName | Should - BeTrue
124138
@@ -139,4 +153,66 @@ Describe 'Get-Member' {
139153 $MemberData | Should - BeOfType __
140154 }
141155 }
156+ }
157+
158+ Describe ' Get-Command' {
159+ <#
160+ Get-Command
161+
162+ Get-Command is one of the most useful cmdlets for discovery. It allows you to
163+ list all available commands, specify a module to look for available commands in,
164+ and filter based on command name, module name, etc.
165+
166+ As the vast majority of PowerShell commands are packaged with help files, it is
167+ also an invaluable tool in finding possible help topics to look up in the first
168+ place!
169+
170+ When looking for related commands, use of the -Verb and -Noun search options
171+ is often easier than figuring out how many wildcards you need in a -Name search.
172+ #>
173+ BeforeAll {
174+ # Try calling Get-Command in a PowerShell console to see the typical output!
175+ $Commands = Get-Command
176+ }
177+
178+ It ' lists available commands' {
179+ $Commands.Count | Should - Be __
180+ $Commands [7 ].Name | Should - Be ' __'
181+ }
182+
183+ It ' indicates the type of command' {
184+ $CommandTypes = $Commands | Select-Object - ExpandProperty CommandType | Sort-Object - Unique
185+
186+ @ (' __' , ' __' , ' Cmdlet' ) | Should - Be $CommandTypes
187+ }
188+
189+ It ' can filter the output by keywords' {
190+ $Command = Get-Command - Name " *-Child*"
191+ $CimCommand = Get-Command - Name ' __'
192+
193+ $Command.CommandType | Should - Be ' Cmdlet'
194+ $Command.Name | Should - Be ' __'
195+ $CimCommand.Name | Should - Be ' Get-CimClass'
196+ }
197+
198+ It ' can look for commands by verb' {
199+ $GetCommands = Get-Command - Verb ' Get'
200+ $GetCommands.Count | Should - Be __
201+
202+ $GetCommands [4 ].Name | Should - Be ' __'
203+ }
204+
205+ It ' can look for commands by noun' {
206+ $DateCommands = Get-Command - Noun ' Date'
207+
208+ $DateCommands.Count | Should - Be __
209+ $DateCommands [0 ].Name | Should - Be ' __'
210+ }
211+
212+ It ' can look for commands by module' {
213+ $KoanCommands = Get-Command - Module ' PSKoans'
214+
215+ $KoanCommands.Count | Should - Be __
216+ $KoanCommands.Name | Should - Be @ (' __' , ' __' , ' __' , ' __' )
217+ }
142218}
0 commit comments