1+ <#
2+ . Synopsis
3+ Gets Module Exports
4+ . Description
5+ Gets Exported Commands from a module.
6+ . EXAMPLE
7+ .> {
8+ $PipeScriptModule = Get-Module PipeScript
9+ $exports = [ModuleExports()]$PipeScriptModule
10+ $exports
11+ }
12+ #>
13+ [CmdletBinding (DefaultParameterSetName = ' None' , PositionalBinding = $false )]
14+ [ValidateScript ({
15+ $val = $_
16+ if (
17+ ($val.Parent -is [Management.Automation.Language.AttributedExpressionAst ]) -and
18+ ($val.Parent.Attribute.TypeName.Name -in ' ModuleExport' , ' GetExport' , ' GetExports' , ' ListExports' , ' ModuleExport' , ' GetModuleExport' , ' GetModuleExports' )
19+ ) {
20+ return $true
21+ }
22+ return $false
23+ })]
24+ [Alias (' GetExport' , ' GetExports' , ' ListExport' , ' ListExports' , ' ModuleExport' , ' GetModuleExport' , ' GetModuleExports' )]
25+ param (
26+ # The command type
27+ [Parameter (Position = 0 )]
28+ [Management.Automation.CommandTypes []]
29+ $CommandType = @ (' Alias' , ' Function' , ' Cmdlet' ),
30+
31+ # A VariableExpression. This variable must contain a module.
32+ [Parameter (Mandatory , ValueFromPipeline , ParameterSetName = ' VariableExpressionAST' )]
33+ [Management.Automation.Language.VariableExpressionAST ]
34+ $VariableAST
35+ )
36+
37+ process {
38+
39+ $var = $VariableAST.Extent.ToString ()
40+ [scriptblock ]::Create($ (
41+ {
42+ @ (
43+ if ($var -isnot [Management.Automation.PSModuleInfo ]) {
44+ Write-Error " '$var ' must be a [Management.Automation.PSModuleInfo]"
45+ } elseif ($var.ExportedCommands.Count ) {
46+ foreach ($cmd in $var.ExportedCommands.Values ) {
47+ if ($cmd.CommandType -in $CommandType ) {
48+ $cmd
49+ }
50+ }
51+ } else {
52+ foreach ($cmd in $ExecutionContext.SessionState.InvokeCommand.GetCommands (' *' , ' Function,Cmdlet' , $true )) {
53+ if ($cmd.Module -ne $var ) { continue }
54+ if ($CommandType -contains ' Alias' -and $cmd.ScriptBlock.Attributes.AliasNames ) {
55+ foreach ($aliasName in $cmd.ScriptBlock.Attributes.AliasNames ) {
56+ $ExecutionContext.SessionState.InvokeCommand.GetCommand ($aliasName , ' Alias' )
57+ }
58+ }
59+ if ($CommandType -contains $cmd.CommandType ) {
60+ $cmd
61+ }
62+ }
63+ })
64+ } -replace ' \$var' , " $var " -replace ' \$CommandType' , " '$ ( $CommandType -join " ','" ) '" ))
65+ }
0 commit comments