1
1
ValidateScriptBlock
2
2
-------------------
3
+
4
+
5
+
6
+
3
7
### Synopsis
4
8
Validates Script Blocks
5
9
10
+
11
+
6
12
---
13
+
14
+
7
15
### Description
8
16
9
17
Validates Script Blocks for a number of common scenarios.
10
18
19
+
20
+
11
21
---
22
+
23
+
12
24
### Examples
13
25
#### EXAMPLE 1
14
26
``` PowerShell
@@ -43,7 +55,11 @@ $ScriptBlock
43
55
```
44
56
$ScriptBlock
45
57
} | .>PipeScript
58
+
59
+
46
60
---
61
+
62
+
47
63
### Parameters
48
64
#### ** DataLanguage**
49
65
@@ -52,205 +68,185 @@ This will attempt to recreate the Script Block as a datalanguage block and execu
52
68
53
69
54
70
55
- > ** Type** : ``` [Switch] ```
56
71
57
- > ** Required** : false
58
72
59
- > ** Position** : named
60
73
61
- > ** PipelineInput** : false
74
+ | Type | Required| Position| PipelineInput| Aliases|
75
+ | ----------| --------| --------| -------------| -------|
76
+ | ` [Switch] ` | false | named | false | Safe |
62
77
63
78
64
79
65
- ---
66
80
#### ** ParameterOnly**
67
81
68
82
If set, will ensure that the [ ScriptBlock] only has parameters
69
83
70
84
71
85
72
- > ** Type** : ``` [Switch] ```
73
86
74
- > ** Required** : false
75
87
76
- > ** Position** : named
77
88
78
- > ** PipelineInput** : false
89
+ | Type | Required| Position| PipelineInput| Aliases |
90
+ | ----------| --------| --------| -------------| --------------|
91
+ | ` [Switch] ` | false | named | false | OnlyParameters|
79
92
80
93
81
94
82
- ---
83
95
#### ** NoBlock**
84
96
85
97
If set, will ensure that the [ ScriptBlock] has no named blocks.
86
98
87
99
88
100
89
- > ** Type** : ``` [Switch] ```
90
101
91
- > ** Required** : false
92
102
93
- > ** Position** : named
94
103
95
- > ** PipelineInput** : false
104
+ | Type | Required| Position| PipelineInput| Aliases |
105
+ | ----------| --------| --------| -------------| --------|
106
+ | ` [Switch] ` | false | named | false | NoBlocks|
96
107
97
108
98
109
99
- ---
100
110
#### ** NoParameter**
101
111
102
112
If set, will ensure that the [ ScriptBlock] has no parameters.
103
113
104
114
105
115
106
- > ** Type** : ``` [Switch] ```
107
116
108
- > ** Required** : false
109
117
110
- > ** Position** : named
111
118
112
- > ** PipelineInput** : false
119
+ | Type | Required| Position| PipelineInput| Aliases |
120
+ | ----------| --------| --------| -------------| ------------------------|
121
+ | ` [Switch] ` | false | named | false | NoParameters<br />NoParam|
113
122
114
123
115
124
116
- ---
117
125
#### ** IncludeCommand**
118
126
119
- > ** Type** : ``` [Object] ```
120
127
121
- > ** Required** : false
122
128
123
- > ** Position** : named
124
129
125
- > ** PipelineInput** : false
130
+ | Type | Required| Position| PipelineInput|
131
+ | ----------| --------| --------| -------------|
132
+ | ` [Object] ` | false | named | false |
126
133
127
134
128
135
129
- ---
130
136
#### ** ExcludeCommand**
131
137
132
- > ** Type** : ``` [Object] ```
133
138
134
- > ** Required** : false
135
139
136
- > ** Position** : named
137
140
138
- > ** PipelineInput** : false
141
+ | Type | Required| Position| PipelineInput|
142
+ | ----------| --------| --------| -------------|
143
+ | ` [Object] ` | false | named | false |
139
144
140
145
141
146
142
- ---
143
147
#### ** IncludeType**
144
148
145
149
If set, will ensure that the script block contains types in this list.
146
150
Passing -IncludeType without -ExcludeType will make -ExcludeType default to * .
147
151
148
152
149
153
150
- > ** Type** : ``` [Object] ```
151
154
152
- > ** Required** : false
153
155
154
- > ** Position** : named
155
156
156
- > ** PipelineInput** : false
157
+ | Type | Required| Position| PipelineInput|
158
+ | ----------| --------| --------| -------------|
159
+ | ` [Object] ` | false | named | false |
157
160
158
161
159
162
160
- ---
161
163
#### ** ExcludeType**
162
164
163
165
If set, will ensure that the script block does not use the types in this list.
164
166
Passing -IncludeType without -ExcludeType will make -ExcludeType default to * .
165
167
166
168
167
169
168
- > ** Type** : ``` [Object] ```
169
170
170
- > ** Required** : false
171
171
172
- > ** Position** : named
173
172
174
- > ** PipelineInput** : false
173
+ | Type | Required| Position| PipelineInput|
174
+ | ----------| --------| --------| -------------|
175
+ | ` [Object] ` | false | named | false |
175
176
176
177
177
178
178
- ---
179
179
#### ** NoLoop**
180
180
181
181
If set, will ensure that the ScriptBlock does not contain any loops.
182
182
183
183
184
184
185
- > ** Type** : ``` [Switch] ```
186
185
187
- > ** Required** : false
188
186
189
- > ** Position** : named
190
187
191
- > ** PipelineInput** : false
188
+ | Type | Required| Position| PipelineInput| Aliases|
189
+ | ----------| --------| --------| -------------| -------|
190
+ | ` [Switch] ` | false | named | false | NoLoops|
192
191
193
192
194
193
195
- ---
196
194
#### ** NoWhileLoop**
197
195
198
196
If set, will ensure that the ScriptBlock does not contain any do or while loops.
199
197
200
198
201
199
202
- > ** Type** : ``` [Switch] ```
203
200
204
- > ** Required** : false
205
201
206
- > ** Position** : named
207
202
208
- > ** PipelineInput** : false
203
+ | Type | Required| Position| PipelineInput| Aliases |
204
+ | ----------| --------| --------| -------------| ---------------------------------------|
205
+ | ` [Switch] ` | false | named | false | NoWhileLoops<br />NoDoLoops<br />NoDoLoop|
209
206
210
207
211
208
212
- ---
213
209
#### ** AstCondition**
214
210
215
211
One or more AST conditions to validate.
216
212
If no results are found or the condition throws, the script block will be considered invalid.
217
213
218
214
219
215
220
- > ** Type** : ``` [ScriptBlock[]] ```
221
216
222
- > ** Required** : false
223
217
224
- > ** Position** : named
225
218
226
- > ** PipelineInput** : false
219
+ | Type | Required| Position| PipelineInput| Aliases |
220
+ | -----------------| --------| --------| -------------| -----------------------|
221
+ | ` [ScriptBlock[]] ` | false | named | false | AstConditions<br />IfAst|
227
222
228
223
229
224
230
- ---
231
225
#### ** VariableAST**
232
226
233
227
A VariableExpression. If provided, the Validation attributes will apply to this variable.
234
228
235
229
236
230
237
- > ** Type** : ``` [VariableExpressionAst] ```
238
231
239
- > ** Required** : true
240
232
241
- > ** Position** : named
242
233
243
- > ** PipelineInput** : true (ByValue)
234
+ | Type | Required| Position| PipelineInput |
235
+ | -------------------------| --------| --------| --------------|
236
+ | ` [VariableExpressionAst] ` | true | named | true (ByValue)|
237
+
238
+
244
239
245
240
246
241
247
242
---
243
+
244
+
248
245
### Syntax
249
246
``` PowerShell
250
247
ValidateScriptBlock [-DataLanguage] [-ParameterOnly] [-NoBlock] [-NoParameter] [-IncludeCommand <Object>] [-ExcludeCommand <Object>] [-IncludeType <Object>] [-ExcludeType <Object>] [-NoLoop] [-NoWhileLoop] [-AstCondition <ScriptBlock[]>] [<CommonParameters>]
251
248
```
252
249
``` PowerShell
253
250
ValidateScriptBlock [-DataLanguage] [-ParameterOnly] [-NoBlock] [-NoParameter] [-IncludeCommand <Object>] [-ExcludeCommand <Object>] [-IncludeType <Object>] [-ExcludeType <Object>] [-NoLoop] [-NoWhileLoop] [-AstCondition <ScriptBlock[]>] -VariableAST <VariableExpressionAst> [<CommonParameters>]
254
251
```
255
- ---
256
252
0 commit comments