1+ # Monkey365 - the PowerShell Cloud Security Tool for Azure and Microsoft 365 (copyright 2022) by Juan Garrido
2+ #
3+ # Licensed under the Apache License, Version 2.0 (the "License");
4+ # you may not use this file except in compliance with the License.
5+ # You may obtain a copy of the License at
6+ #
7+ # http://www.apache.org/licenses/LICENSE-2.0
8+ #
9+ # Unless required by applicable law or agreed to in writing, software
10+ # distributed under the License is distributed on an "AS IS" BASIS,
11+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ # See the License for the specific language governing permissions and
13+ # limitations under the License.
14+
15+ Function New-DynamicParameter {
16+ param (
17+ [Parameter (Mandatory = $true , HelpMessage = " Name" )]
18+ [string ] $Name ,
19+
20+ [Parameter (Mandatory = $true , HelpMessage = " Type" )]
21+ [type ] $Type ,
22+
23+ [Parameter (Mandatory = $false , HelpMessage = " Alias" )]
24+ [string []] $Alias ,
25+
26+ [Parameter (Mandatory = $false , HelpMessage = " Validate" )]
27+ [string []] $ValidateSet ,
28+
29+ [Parameter (Mandatory = $false , HelpMessage = " Validate Script" )]
30+ [scriptblock ] $ValidateScript
31+ )
32+
33+ $attributes = [System.Collections.ObjectModel.Collection [System.Attribute ]]::new()
34+
35+ $paramAttr = [System.Management.Automation.ParameterAttribute ]::new()
36+ $paramAttr.Mandatory = $false
37+ $attributes.Add ($paramAttr )
38+
39+ If ($Alias ) {
40+ $attributes.Add ([System.Management.Automation.AliasAttribute ]::new($Alias ))
41+ }
42+
43+ If ($ValidateSet ) {
44+ $attributes.Add ([System.Management.Automation.ValidateSetAttribute ]::new([string []]$ValidateSet ))
45+ }
46+
47+ If ($ValidateScript ) {
48+ $attributes.Add ([System.Management.Automation.ValidateScriptAttribute ]::new($ValidateScript ))
49+ }
50+
51+ [System.Management.Automation.RuntimeDefinedParameter ]::new(
52+ $Name ,
53+ $Type ,
54+ $attributes
55+ )
56+ }
0 commit comments