Repository navigation
Expand file tree
/
Copy pathabout_psmoduledevelopment.help.txt
More file actions
163 lines (112 loc) · 6.21 KB
/
Copy pathabout_psmoduledevelopment.help.txt
File metadata and controls
163 lines (112 loc) · 6.21 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
TOPIC
about_psmoduledevelopment
SHORT DESCRIPTION
Explains how the PSModuleDevelopment module can enhance your module
development experience
LONG DESCRIPTION
Welcome to the introductory guide of the PSModuleDevelopment module.
This module is designed to help you develop PowerShell modules faster,
easier and more reliably, than would otherwise be possible.
For brevity's sake, the module shall henceforth be abbreviated to "PSMD"
#-------------------------------------------------------------------------#
# Index #
#-------------------------------------------------------------------------#
- The Little Helpers
- Refactoring
- Gaming the Type System
- Multilingual Help
- The Need for Speed
- Optimizing the debugging cycle
#-------------------------------------------------------------------------#
# The Little Helpers #
#-------------------------------------------------------------------------#
Often it is the small things that make all the difference. PSMD provides a
few small helpers, that can make all the difference:
# find (Find-PSMDFileContent) #
#-----------------------------#
"find" allows you to swiftly search the module you are working on. For
example, the following line:
find "Get-Test"
Will search the entire module for all instances of "Get-Test"
In order to set this up, you need to point the command to where your module
is being stored:
Set-PSMDModulePath -Path "<path to module folder>"
If you want that path to persist across multiple sessions, you can register
it, which will set the same path again each time you import PSMD:
Register-PSFConfig -FullName 'PSModuleDevelopment.Module.Path'
# rss (Restart-PSMDShell) #
#-------------------------#
The best we to reset your test environment is to start a new console. This
can be cumbersome though ... unless you use PSMD, in which case it is a
matter of typing "rss" and sending the command.
You can further use one (or multiple) of its parameters for extra benefit:
- NoExit: Instead of closing the old console, you clone it
- Admin: The new console will be started with elevation
- NoProfile: The new console will not load the user profile
#-------------------------------------------------------------------------#
# Refactoring #
#-------------------------------------------------------------------------#
Sometimes you need to fix something at scale. Globally rename a parameter
maybe? Change the help text for the same parameter across all commands?
This is where the refactoring suite of commands of PSMD comes into play:
- Rename-PSMDParameter
- Set-PSMDCmdletBinding
- Set-PSMDParameterHelp
- Split-PSMDScriptFile
More detailed guidance on how to use them shall follow in a dedicated
article, but they already have full Comment Based Help (with examples).
#-------------------------------------------------------------------------#
# Gaming the Type System #
#-------------------------------------------------------------------------#
Sometimes we need to look beneath the hood of C# and .NET. This is when the
suite of commands dealing with assemblies, types at all come in handy.
# New-PSMDFormatTableDefinition
Give this command any type of object, it will create an XML definition you
can use in your module to style the layout of your objects.
# Expand-PSMDTypeName
Returns the full name of the input object's type, as well as the name of
the types it inherits from, recursively until System.Object.
# Find-PSMDType
Searches assemblies for types.
# Get-PSMDAssembly
Returns the assemblies currently loaded.
# Get-PSMDConstructor
Returns information on the available constructors of a type.
#-------------------------------------------------------------------------#
# Multilingual Help #
#-------------------------------------------------------------------------#
In some instances, you may want to provide multilingual help for your
module. If you're wondering how to do that, here's a guide that will walk
you through the details:
https://allthingspowershell.blogspot.com/2016/08/powershell-modules-multilingual-help.html
That said, the PSMD module ships with a command that lets you test out help
text on commands in multiple languages:
Get-PSMDHelpEx (Alias: hex)
It comes with a few gotchas (the main one being that PowerShell caches the
first help retrieved for a command. Testing help in another language
requires a restart of the console).
#-------------------------------------------------------------------------#
# The Need for Speed #
#-------------------------------------------------------------------------#
Speed matters.
In order to develop high performance code however, you need to have the
tools to measure speed accurately. PowerShell has out of the box a tool
that helps with that: 'Measure-Command'
However, while Measure-Command is powerful (and you really should master it
if you haven't already), sometimes you need to measure many repetitions of
code in deeper details. This is where PSMD comes into play with:
Measure-PSMDCommandEx
It's basically a Measure-Command, but can run the same snippet dozens or
hundreds of time in a row and measure duration statistics (total, average,
minimum, ...).
#-------------------------------------------------------------------------#
# Optimizing the debugging cycle #
#-------------------------------------------------------------------------#
The module provides, using its *-PSMDModuleDebug commands, a system to
automatedly perform tests. It can reduce the test workflow in your console
window to the simple act of restarting the shell.
For more details on how to set up your computer and module for this
automated testing cycle, see the following blog post:
https://allthingspowershell.blogspot.com/2016/08/module-development-optimizing-test-and.html
KEYWORDS
module development debugging