Extract Functions, Parameters and Help Info from a Module
Morning all! It's been a while since I've written a blog post, mainly due to swapping jobs around and moving house, but now I'm back and keen to get writing again, so here we go.
I've been working on various Powershell related projects which involve a central database storage solution for modules so we can share them easily internally in the business and use them as part of orchestration tools we've written. One of the things we needed to do was create an XML manifest of all functions in a module, their paramters and types and then (if it existed) the help for each paramter so we could pass it into the toolbox.
The following functions extract the data into nice Powershell objects so you can use them however you like.
The first function is Get-ModuleFunctionsandParams and does what it says on the tin.
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 | Function Get-ModuleFunctionsAndParams($ModuleName) { Import-Module $ModuleName $Functions = Get-Command -Module $ModuleName $FuncTable = @() ForEach($Func in $Functions) { $ARow = "" | Select Name,Params $ARow.Name = $Func.Name $Params = @() ForEach($PSet in $Func.ParameterSets) { ForEach($Param in $PSet.Parameters) { $BRow = "" | Select Name,Type $BRow.Name = $Param.Name $BRow.Type = $Param.ParameterType $Params += $BRow } } $ARow.Params = $Params $FuncTable += $ARow } Return $FuncTable } |
This is the Get-ParamterHelp function, you pass in the function name and the variable name you're interested in, and away you go....
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 | Function Get-ParameterHelp($FunctionName,$VariableName) { $Help = Get-Help $FunctionName $Table = @() ForEach($Param in $Help.Parameters.Parameter) { if(-not $VariableName) { $ARow = "" | Select Name,Description,Position,Required $ARow.Name = $Param.Name $ARow.Description = $Param.Description[0].text $ARow.Position = $Param.Position $ARow.Required = $Param.Required $Table += $ARow } Else { if($Param.Name.ToString().ToLower() -eq $VariableName.ToString().ToLower()) { $ARow = "" | Select Name,Description,Position,Required $ARow.Name = $Param.Name $ARow.Description = $Param.Description[0].text $ARow.Position = $Param.Position $ARow.Required = $Param.Required $Table += $ARow } } } Return $Table } |



