@@ -67,8 +67,27 @@ function Create-ModulePsm1
67
67
$template = $template -replace " %DATE%" , [string ](Get-Date )
68
68
$template = $template -replace " %IMPORTED-DEPENDENCIES%" , $importedModules
69
69
70
- if ($AddDefaultParameters )
71
- {
70
+ $contructedCommands = Find-DefaultResourceGroupCmdlets - AddDefaultParameters $AddDefaultParameters - ModuleMetadata $ModuleMetadata - ModulePath $ModulePath
71
+ $template = $template -replace " %COMMANDS%" , $contructedCommands
72
+
73
+ Write-Host " Writing psm1 manifest to $templateOutputPath "
74
+ $template | Out-File - FilePath $templateOutputPath - Force
75
+ $file = Get-Item - Path $templateOutputPath
76
+ }
77
+ }
78
+
79
+ function Find-DefaultResourceGroupCmdlets
80
+ {
81
+ [CmdletBinding ()]
82
+ param (
83
+ [bool ]$AddDefaultParameters ,
84
+ [Hashtable ]$ModuleMetadata ,
85
+ [string ]$ModulePath
86
+ )
87
+ PROCESS
88
+ {
89
+ if ($AddDefaultParameters )
90
+ {
72
91
$nestedModules = $ModuleMetadata.NestedModules
73
92
$AllCmdlets = @ ()
74
93
$nestedModules | ForEach-Object {
@@ -78,47 +97,55 @@ function Create-ModulePsm1
78
97
$AllCmdlets += $dllCmdlets
79
98
}
80
99
81
- $FilteredCommands = @ ()
82
- $AllCmdlets | ForEach-Object {
83
- $rgParameter = $_.GetProperties () | Where-Object {$_.Name -eq " ResourceGroupName" }
84
- if ($rgParameter -ne $null ) {
85
- $parameterSets = $rgParameter.CustomAttributes | Where-Object {$_.AttributeType.Name -eq " ParameterAttribute" }
86
- $isMandatory = $true
87
- $parameterSets | ForEach-Object {
88
- $hasParameterSet = $_.NamedArguments | Where-Object {$_.MemberName -eq " ParameterSetName" }
89
- $MandatoryParam = $_.NamedArguments | Where-Object {$_.MemberName -eq " Mandatory" }
90
- if (($hasParameterSet -ne $null ) -or (! $MandatoryParam.TypedValue.Value )) {
91
- $isMandatory = $false
92
- }
93
- }
94
- if ($isMandatory ) {
95
- $FilteredCommands += $_
96
- }
100
+ $FilteredCommands = $AllCmdlets | Where-Object {Test-RequiredParameter - Cmdlet $_ }
101
+
102
+ if ($FilteredCommands.Length -eq 0 ) {
103
+ $contructedCommands = " @()"
104
+ }
105
+ else {
106
+ $contructedCommands = " @("
107
+ $FilteredCommands | ForEach-Object {
108
+ $contructedCommands += " '" + $_.GetCustomAttributes (" System.Management.Automation.CmdletAttribute" ).VerbName + " -" + $_.GetCustomAttributes (" System.Management.Automation.CmdletAttribute" ).NounName + " :ResourceGroupName" + " ',"
97
109
}
110
+ $contructedCommands = $contructedCommands -replace " .$" , " )"
98
111
}
99
-
100
- if ($FilteredCommands.Length -eq 0 ) {
101
- $contructedCommands = " @()"
112
+
113
+ return $contructedCommands
102
114
}
115
+
103
116
else {
104
- $contructedCommands = " @("
105
- $FilteredCommands | ForEach-Object {
106
- $contructedCommands += " '" + $_.GetCustomAttributes (" System.Management.Automation.CmdletAttribute" ).VerbName + " -" + $_.GetCustomAttributes (" System.Management.Automation.CmdletAttribute" ).NounName + " :ResourceGroupName" + " ',"
107
- }
108
- $contructedCommands = $contructedCommands -replace " .$" , " )"
117
+ return " @()"
109
118
}
110
-
111
- $template = $template -replace " %COMMANDS%" , $contructedCommands
112
- }
119
+ }
120
+ }
113
121
114
- else {
115
- $template = $template -replace " %COMMANDS%" , " @()"
116
- }
117
-
118
- Write-Host " Writing psm1 manifest to $templateOutputPath "
119
- $template | Out-File - FilePath $templateOutputPath - Force
120
- $file = Get-Item - Path $templateOutputPath
121
- }
122
+ function Test-RequiredParameter
123
+ {
124
+ [CmdletBinding ()]
125
+ param (
126
+ [Object ]$Cmdlet
127
+ )
128
+
129
+ PROCESS
130
+ {
131
+ $rgParameter = $Cmdlet.GetProperties () | Where-Object {$_.Name -eq " ResourceGroupName" }
132
+ if ($rgParameter -ne $null ) {
133
+ $parameterSets = $rgParameter.CustomAttributes | Where-Object {$_.AttributeType.Name -eq " ParameterAttribute" }
134
+ $isMandatory = $true
135
+ $parameterSets | ForEach-Object {
136
+ $hasParameterSet = $_.NamedArguments | Where-Object {$_.MemberName -eq " ParameterSetName" }
137
+ $MandatoryParam = $_.NamedArguments | Where-Object {$_.MemberName -eq " Mandatory" }
138
+ if (($hasParameterSet -ne $null ) -or (! $MandatoryParam.TypedValue.Value )) {
139
+ $isMandatory = $false
140
+ }
141
+ }
142
+ if ($isMandatory ) {
143
+ return $true
144
+ }
145
+ }
146
+
147
+ return $false
148
+ }
122
149
}
123
150
124
151
function Create-MinimumVersionEntry
0 commit comments