Skip to content

Commit 89f27bc

Browse files
authored
Markdown fixes
1 parent af347d1 commit 89f27bc

File tree

1 file changed

+42
-39
lines changed

1 file changed

+42
-39
lines changed

Style-Guide/Function-Structure.md

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Avoid using the `return` keyword in your functions. Just place the object variable on its own.
44

55
When declaring simple functions leave a space between the function name and the parameters.
6-
6+
77
```PowerShell
88
function MyFunction ($param1, $param2) {
99
...
@@ -12,14 +12,14 @@ function MyFunction ($param1, $param2) {
1212

1313
### Advanced Functions
1414

15-
For Advanced Functions and scripts use the format of **<verb-<noun>** for
15+
For Advanced Functions and scripts use the format of **\<verb\>-\<noun\>** for
1616
naming. For a list of approved verbs the cmdlet `Get-Verb` will list
1717
them. On the noun side it can be composed of more than one joined word
1818
using Pascal Case and only singular nouns.
1919

2020
In Advanced Functions do not use the keyword `return` to return an object.
2121

22-
In Advanced Functions you return objects inside the `Process {}` block
22+
In Advanced Functions you return objects inside the `Process {}` block
2323
and not in `Begin {}` or `End {}` since it defeats the advantage of the pipeline.
2424

2525
```PowerShell
@@ -82,7 +82,7 @@ function Get-USCitizenCapability {
8282

8383
#### Always have at least a `process {}` code block if any parameters takes values from the Pipeline.
8484

85-
#### Specify an OutputType attribute if the advanced function returns an object or collection of objects.
85+
#### Specify an OutputType attribute if the advanced function returns an object or collection of objects.
8686

8787
If the function returns different object types depending on the parameter set provide one per parameter set.
8888

@@ -98,22 +98,22 @@ function Get-User {
9898
[CmdletBinding(DefaultParameterSetName = "ID")]
9999
[OutputType("System.Int32", ParameterSetName = "ID")]
100100
[OutputType([String], ParameterSetName = "Name")]
101-
param (
101+
param (
102102
[parameter(Mandatory = $true, ParameterSetName = "ID")]
103103
[Int[]]
104104
$UserID,
105105
106106
[parameter(Mandatory = $true, ParameterSetName = "Name")]
107107
[String[]]
108108
$UserName
109-
)
109+
)
110110
<# function body #>
111111
}
112112
```
113113

114114
#### When using advanced functions or scripts with CmdletBinding attribute avoid validating parameters in the body of the script when possible and use parameter validation attributes instead.
115115

116-
* **AllowNull** Validation Attribute
116+
* **AllowNull** Validation Attribute
117117

118118
The AllowNull attribute allows the value of a mandatory parameter to be null ($null).
119119

@@ -123,10 +123,10 @@ function Get-User {
123123
[AllowNull()]
124124
[String]
125125
$ComputerName
126-
)
126+
)
127127
```
128128

129-
* **AllowEmptyString** Validation Attribute
129+
* **AllowEmptyString** Validation Attribute
130130

131131
The AllowEmptyString attribute allows the value of a mandatory parameter to be an empty string ("").
132132

@@ -136,10 +136,10 @@ function Get-User {
136136
[AllowEmptyString()]
137137
[String]
138138
$ComputerName
139-
)
139+
)
140140
```
141141

142-
* **AllowEmptyCollection** Validation Attribute
142+
* **AllowEmptyCollection** Validation Attribute
143143

144144
The AllowEmptyCollection attribute allows the value of a mandatory parameter to be an empty collection (@()).
145145

@@ -149,28 +149,28 @@ function Get-User {
149149
[AllowEmptyCollection()]
150150
[String[]]
151151
$ComputerName
152-
)
152+
)
153153
```
154154

155-
* **ValidateCount** Validation Attribute
155+
* **ValidateCount** Validation Attribute
156156

157157
The ValidateCount attribute specifies the minimum and maximum number
158158
of parameter values that a parameter accepts. Windows PowerShell
159159
generates an error if the number of parameter values in the command that
160-
calls the function is outside that range.
160+
calls the function is outside that range.
161161

162162
```PowerShell
163163
param (
164164
[Parameter(Mandatory = $true)]
165165
[ValidateCount(1,5)]
166166
[String[]]
167167
$ComputerName
168-
)
168+
)
169169
```
170170

171-
* **ValidateLength** Validation Attribute
171+
* **ValidateLength** Validation Attribute
172172

173-
The ValidateLength attribute specifies the minimum and maximum number
173+
The ValidateLength attribute specifies the minimum and maximum number
174174
of characters in a parameter or variable value. Windows PowerShell generates an
175175
error if the length of a value specified for a parameter or a variable
176176
is outside of the range.
@@ -181,39 +181,41 @@ function Get-User {
181181
[ValidateLength(1,10)]
182182
[String[]]
183183
$ComputerName
184-
)
184+
)
185185
```
186186

187-
* **ValidatePattern** Validation Attribute
187+
* **ValidatePattern** Validation Attribute
188188

189189
The ValidatePattern attribute specifies a regular expression that
190190
is compared to the parameter or variable value. Windows PowerShell generates
191-
an error if the value does not match the regular expression
192-
pattern.
191+
an error if the value does not match the regular expression
192+
pattern.
193+
193194
```PowerShell
194195
param (
195196
[Parameter(Mandatory = $true)]
196197
[ValidatePattern("[0-9][0-9][0-9][0-9]")]
197198
[String[]]
198199
$ComputerName
199-
)
200+
)
200201
```
201202

202-
* **ValidateRange** Validation Attribute
203+
* **ValidateRange** Validation Attribute
203204

204205
The ValidateRange attribute specifies a numeric range for each
205206
parameter or variable value. Windows PowerShell generates an error
206-
if any value is outside that range.
207+
if any value is outside that range.
208+
207209
```PowerShell
208210
param (
209211
[Parameter(Mandatory = $true)]
210212
[ValidateRange(0,10)]
211213
[Int]
212214
$Attempts
213-
)
215+
)
214216
```
215217

216-
* **ValidateScript** Validation Attribute
218+
* **ValidateScript** Validation Attribute
217219

218220
The ValidateScript attribute specifies a script that is used
219221
to validate a parameter or variable value. Windows PowerShell
@@ -230,12 +232,12 @@ function Get-User {
230232
[ValidateScript({$_ -ge (get-date)})]
231233
[DateTime]
232234
$EventDate
233-
)
235+
)
234236
```
235237

236-
* **ValidateSet** Attribute
238+
* **ValidateSet** Attribute
237239

238-
The ValidateSet attribute specifies a set of valid values for a
240+
The ValidateSet attribute specifies a set of valid values for a
239241
parameter or variable. Windows PowerShell generates an error if a
240242
parameter or variable value does not match a value in the set. In
241243
the following example, the value of the Detail parameter can only
@@ -247,36 +249,38 @@ function Get-User {
247249
[ValidateSet("Low", "Average", "High")]
248250
[String[]]
249251
$Detail
250-
)
252+
)
251253
```
252254

253-
* **ValidateNotNull** Validation Attribute
255+
* **ValidateNotNull** Validation Attribute
254256

255257
The ValidateNotNull attribute specifies that the parameter
256258
value cannot be null ($null). Windows PowerShell generates an
257-
error if the parameter value is null.
259+
error if the parameter value is null.
258260

259261
The ValidateNotNull attribute is designed to be used when the
260262
type of the parameter value is not specified or when the specified
261263
type will accept a value of Null. (If you specify a type that will
262264
not accept a null value, such as a string, the null value will be
263265
rejected without the ValidateNotNull attribute, because it does not
264-
match the specified type.)
266+
match the specified type.)
267+
265268
```PowerShell
266269
param (
267270
[Parameter(Mandatory = $true)]
268271
[ValidateNotNull()]
269272
$ID
270-
)
273+
)
271274
```
272275

273-
* **ValidateNotNullOrEmpty** Validation Attribute
276+
* **ValidateNotNullOrEmpty** Validation Attribute
274277

275-
The ValidateNotNullOrEmpty attribute specifies that the parameter
278+
The ValidateNotNullOrEmpty attribute specifies that the parameter
276279
value cannot be null ($null) and cannot be an empty string ("").
277-
Windows PowerShell generates an error if the parameter is used in
280+
Windows PowerShell generates an error if the parameter is used in
278281
a function call, but its value is null, an empty string, or an empty
279-
array.
282+
array.
283+
280284
```PowerShell
281285
param (
282286
[Parameter(Mandatory = $true)]
@@ -285,4 +289,3 @@ function Get-User {
285289
$UserName
286290
)
287291
```
288-

0 commit comments

Comments
 (0)