en-AU/about_PSDocs_Selectors.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
TOPIC
    about_psdocs_selectors
 
SHORT DESCRIPTION
    Describes PSDocs Selectors including how to use and author them.
 
LONG DESCRIPTION
    PSDocs executes document to validate an object from input. When evaluating
    an object from input, PSDocs can use selectors to perform complex matches of
    an object.
    - A selector is a YAML-based expression that evaluates an object.
    - Each selector is comprised of nested conditions, operators, and comparison properties.
    - Selectors must use one or more available conditions with a comparison
    property to evaluate the object.
    - Optionally a condition can be nested in an operator.
    - Operators can be nested within other operators.
    The following conditions are available:
    -
    Contains
    -
    Equals
    -
    EndsWith
    -
    Exists
    -
    Greater
    -
    GreaterOrEquals
    -
    HasValue
    -
    In
    -
    IsLower
    -
    IsString
    -
    IsUpper
    -
    Less
    -
    LessOrEquals
    -
    Match
    -
    NotEquals
    -
    NotIn
    -
    NotMatch
    -
    StartsWith
    The following operators are available:
-
    AllOf
    -
    AnyOf
    -
    Not
    The following comparison properties are available:
-
    Field
    Currently the following limitations apply:
    - Selectors can only evaluate a field of the target object. The following
    examples can not be evaluated by selectors: - State variables such as
    `$PSDocs`.
 
    USING SELECTORS AS PRE-CONDITIONS
    Selectors can be referenced by name as a document pre-condition by using the
    `-With` parameter. For example:
 
    Document 'SampleWithSelector' -With 'BasicSelector' {
        # Additional content
    }
 
    Selector pre-conditions can be used together with script block
    pre-conditions. If one or more selector pre-conditions are used, they are
    evaluated before script block pre-conditions.
 
    DEFINING SELECTORS
    Selectors are defined in YAML and can be included within a module or
    standalone `.Doc.yaml` file. In either case, define a selector within a file
    ending with the `.Doc.yaml` extension.
    Use the following template to define a selector:
 
```yaml
SYNOPSIS: {{ SYNOPSIS }}
    apiVersion: github.com/microsoft/PSDocs/v1 kind: Selector metadata: name:
    '{{ Name }}' spec: if: { }
 
    Within the `if` object, one or more conditions or logical operators can be used.
     
    ### AllOf
     
    The `allOf` operator is used to require all nested expressions to match.
    When any nested expression does not match, `allOf` does not match.
    This is similar to a logical _and_ operation.
     
    Syntax:
 
    yaml allOf: <expression[]>
 
    For example:
 
    yaml apiVersion: github.com/microsoft/PSDocs/v1 kind: Selector metadata:
    name: 'ExampleAllOf' spec: if: allOf: # Both Name and Description
    must exist. - field: 'Name' exists: true - field:
    'Description' exists: true
 
    ### AnyOf
     
    The `anyOf` operator is used to require one or more nested expressions to match.
    When any nested expression matches, `allOf` matches.
    This is similar to a logical _or_ operation.
     
    Syntax:
 
    yaml anyOf: <expression[]>
 
    For example:
 
    yaml apiVersion: github.com/microsoft/PSDocs/v1 kind: Selector metadata:
    name: 'ExampleAnyOf' spec: if: anyOf: # Name and/ or
    AlternativeName must exist. - field: 'Name' exists: true -
    field: 'AlternativeName' exists: true
 
    ### Contains
     
    The `contains` condition can be used to determine if the operand contains a specified sub-string.
    One or more strings to compare can be specified.
     
    Syntax:
 
    yaml contains: <string | array>
 
    - If the operand is a field, and the field does not exist, _contains_ always returns `false`.
     
    For example:
 
    yaml apiVersion: github.com/microsoft/PSDocs/v1 kind: Selector metadata:
    name: 'ExampleContains' spec: if: anyOf: - field: 'url'
    contains: '/azure/' - field: 'url' contains: - 'github.io'
        - 'github.com'
 
    ### Equals
     
    The `equals` condition can be used to compare if a field is equal to a supplied value.
     
    Syntax:
 
    yaml equals: <string | int | bool>
 
    For example:
 
    yaml apiVersion: github.com/microsoft/PSDocs/v1 kind: Selector metadata:
    name: 'ExampleEquals' spec: if: field: 'Name' equals:
    'TargetObject1'
 
    ### EndsWith
     
    The `endsWith` condition can be used to determine if the operand ends with a specified string.
    One or more strings to compare can be specified.
     
    Syntax:
 
    yaml endsWith: <string | array>
 
    - If the operand is a field, and the field does not exist, _endsWith_ always returns `false`.
     
    For example:
 
    yaml apiVersion: github.com/microsoft/PSDocs/v1 kind: Selector metadata:
    name: 'ExampleEndsWith' spec: if: anyOf: - field: 'hostname'
    endsWith: '.com' - field: 'hostname' endsWith: - '.com.au'
        - '.com'
 
    ### Exists
     
    The `exists` condition determines if the specified field exists.
     
    Syntax:
 
    yaml exists: <bool>
 
    - When `exists: true`, exists will return `true` if the field exists.
    - When `exists: false`, exists will return `true` if the field does not exist.
     
    For example:
 
    yaml apiVersion: github.com/microsoft/PSDocs/v1 kind: Selector metadata:
    name: 'ExampleExists' spec: if: field: 'Name' exists: true
 
    ### Field
     
    The comparison property `field` is used with a condition to determine field of the object to evaluate.
    A field can be:
     
    - A property name.
    - A key within a hashtable or dictionary.
    - An index in an array or collection.
    - A nested path through an object.
     
    Syntax:
 
    yaml field: <string>
 
    For example:
 
    yaml apiVersion: github.com/microsoft/PSDocs/v1 kind: Selector metadata:
    name: 'ExampleField' spec: if: field:
    'Properties.securityRules[0].name' exists: true
 
    ### Greater
     
    Syntax:
 
    yaml greater: <int>
 
    For example:
 
    yaml apiVersion: github.com/microsoft/PSDocs/v1 kind: Selector metadata:
    name: 'ExampleGreater' spec: if: field: 'Name' greater: 3
 
    ### GreaterOrEquals
     
    Syntax:
 
    yaml greaterOrEquals: <int>
 
    For example:
 
    yaml apiVersion: github.com/microsoft/PSDocs/v1 kind: Selector metadata:
    name: 'ExampleGreaterOrEquals' spec: if: field: 'Name'
    greaterOrEquals: 3
 
    ### HasValue
     
    The `hasValue` condition determines if the field exists and has a non-empty value.
     
    Syntax:
 
    yaml hasValue: <bool>
 
    - When `hasValue: true`, hasValue will return `true` if the field is not empty.
    - When `hasValue: false`, hasValue will return `true` if the field is empty.
     
    For example:
 
    yaml apiVersion: github.com/microsoft/PSDocs/v1 kind: Selector metadata:
    name: 'ExampleHasValue' spec: if: field: 'Name' hasValue: true
 
    ### In
     
    The `in` condition can be used to compare if a field contains one of the specified values.
     
    Syntax:
 
    yaml in: <array>
 
    For example:
 
    yaml apiVersion: github.com/microsoft/PSDocs/v1 kind: Selector metadata:
    name: 'ExampleIn' spec: if: field: 'Name' in: - 'Value1' -
    'Value2'
 
    ### IsLower
     
    The `isLower` condition determines if the operand is a lowercase string.
     
    Syntax:
 
    yaml isLower: <bool>
 
    - When `isLower: true`, _isLower_ will return `true` if the operand is a lowercase string.
      Non-letter characters are ignored.
    - When `isLower: false`, _isLower_ will return `true` if the operand is not a lowercase string.
    - If the operand is a field, and the field does not exist _isLower_ always returns `false`.
     
    For example:
 
    yaml apiVersion: github.com/microsoft/PSDocs/v1 kind: Selector metadata:
    name: 'ExampleIsLower' spec: if: field: 'Name' isLower: true
 
    ### IsString
     
    The `isString` condition determines if the operand is a string or other type.
     
    Syntax:
 
    yaml isString: <bool>
 
    - When `isString: true`, _isString_ will return `true` if the operand is a string.
    - When `isString: false`, _isString_ will return `true` if the operand is not a string or is null.
    - If the operand is a field, and the field does not exist _isString_ always returns `false`.
     
    For example:
 
    yaml apiVersion: github.com/microsoft/PSDocs/v1 kind: Selector metadata:
    name: 'ExampleIsString' spec: if: field: 'Name' isString: true
 
    ### IsUpper
     
    The `isUpper` condition determines if the operand is an uppercase string.
     
    Syntax:
 
    yaml isUpper: <bool>
 
    - When `isUpper: true`, _isUpper_ will return `true` if the operand is an uppercase string.
      Non-letter characters are ignored.
    - When `isUpper: false`, _isUpper_ will return `true` if the operand is not an uppercase string.
    - If the operand is a field, and the field does not exist _isUpper_ always returns `false`.
     
    For example:
 
    yaml apiVersion: github.com/microsoft/PSDocs/v1 kind: Selector metadata:
    name: 'ExampleIsUpper' spec: if: field: 'Name' isUpper: true
 
    ### Less
     
    Syntax:
 
    yaml less: <int>
 
    For example:
 
    yaml apiVersion: github.com/microsoft/PSDocs/v1 kind: Selector metadata:
    name: 'ExampleLess' spec: if: field: 'Name' less: 3
 
    ### LessOrEquals
     
    Syntax:
 
    yaml lessOrEquals: <int>
 
    For example:
 
    yaml apiVersion: github.com/microsoft/PSDocs/v1 kind: Selector metadata:
    name: 'ExampleLessOrEquals' spec: if: field: 'Name' lessOrEquals:
    3
 
    ### Match
     
    The `match` condition can be used to compare if a field matches a supplied regular expression.
     
    Syntax:
 
    yaml match: <string>
 
    For example:
 
    yaml apiVersion: github.com/microsoft/PSDocs/v1 kind: Selector metadata:
    name: 'ExampleMatch' spec: if: field: 'Name' match: '$(abc|efg)$'
 
    ### Not
     
    The `any` operator is used to invert the result of the nested expression.
    When a nested expression matches, `not` does not match.
    When a nested expression does not match, `not` matches.
     
    Syntax:
 
    yaml not: <expression>
 
    For example:
 
    yaml apiVersion: github.com/microsoft/PSDocs/v1 kind: Selector metadata:
    name: 'ExampleNot' spec: if: not: # The AlternativeName field
    must not exist. field: 'AlternativeName' exists: true
 
    ### NotEquals
     
    The `notEquals` condition can be used to compare if a field is equal to a supplied value.
     
    Syntax:
 
    yaml notEquals: <string | int | bool>
 
    For example:
 
    yaml apiVersion: github.com/microsoft/PSDocs/v1 kind: Selector metadata:
    name: 'ExampleNotEquals' spec: if: field: 'Name' notEquals:
    'TargetObject1'
 
    ### NotIn
     
    The `notIn` condition can be used to compare if a field does not contains one of the specified values.
     
    Syntax:
 
    yaml notIn: <array>
 
    For example:
 
    yaml apiVersion: github.com/microsoft/PSDocs/v1 kind: Selector metadata:
    name: 'ExampleNotIn' spec: if: field: 'Name' notIn: - 'Value1'
        - 'Value2'
 
    ### NotMatch
     
    The `notMatch` condition can be used to compare if a field does not matches a supplied regular expression.
     
    Syntax:
 
    yaml notMatch: <string>
 
    For example:
 
    yaml apiVersion: github.com/microsoft/PSDocs/v1 kind: Selector metadata:
    name: 'ExampleNotMatch' spec: if: field: 'Name' notMatch:
    '$(abc|efg)$'
 
    ### StartsWith
     
    The `startsWith` condition can be used to determine if the operand starts with a specified string.
    One or more strings to compare can be specified.
     
    Syntax:
 
    yaml startsWith: <string | array>
 
    - If the operand is a field, and the field does not exist, _startsWith_ always returns `false`.
     
    For example:
 
    yaml apiVersion: github.com/microsoft/PSDocs/v1 kind: Selector metadata:
    name: 'ExampleStartsWith' spec: if: anyOf: - field: 'url'
    startsWith: 'http' - field: 'url' startsWith: - 'http://'
       - 'https://'
 
    ## EXAMPLES
     
    ### Example Selectors.Doc.yaml
 
    yaml
 
EXAMPLE SELECTORS.DOC.YAML
    ---
 
SYNOPSIS: REQUIRE THE CUSTOMVALUE FIELD.
    apiVersion: github.com/microsoft/PSDocs/v1 kind: Selector metadata: name:
    RequireCustomValue spec: if: field: 'CustomValue' exists: true
    ---
 
SYNOPSIS: REQUIRE A NAME OR ALTERNATIVENAME.
    apiVersion: github.com/microsoft/PSDocs/v1 kind: Selector metadata: name:
    RequireName spec: if: anyOf: - field: 'AlternateName'
    exists: true - field: 'Name' exists: true
    ---
 
SYNOPSIS: REQUIRE A SPECIFIC CUSTOMVALUE
    apiVersion: github.com/microsoft/PSDocs/v1 kind: Selector metadata: name:
    RequireSpecificCustomValue spec: if: field: 'CustomValue' in:
    - 'Value1' - 'Value2' ```
 
NOTE
    An online version of this document is available at
    https://microsoft.github.io/PSDocs/concepts/PSDocs/en-US/about_PSDocs_Selectors.md.
 
SEE ALSO
    -
    Invoke-PSDocs
 
KEYWORDS
    - Selectors
- PSDocs