Skip to content

Instantly share code, notes, and snippets.

@bielawb
Last active December 30, 2016 08:33
Show Gist options
  • Save bielawb/2280408b4c6fa08b4988b73a4af2fe73 to your computer and use it in GitHub Desktop.
Save bielawb/2280408b4c6fa08b4988b73a4af2fe73 to your computer and use it in GitHub Desktop.
Just an attempt to get info about classes defined by a given module.
[CmdletBinding()]
[OutputType([hashtable])]
param (
[string]$Path,
[string]$ClassName = '*'
)
$moduleBase = Split-Path -Path $Path -Parent
Write-Verbose "Module name - $fileName"
$scriptBody = @'
using module {0}
'@ -f $Path
$out = [ordered]@{}
$script = [scriptblock]::Create($scriptBody)
. $script
$assembly = Get-Module |
Where-Object { $_.ModuleBase -eq $moduleBase } |
ForEach-Object ImplementingAssembly |
ForEach-Object GetTypes |
Where-Object {
$_.IsPublic -and
$_.Name -like $ClassName
} |
Sort-Object Name |
ForEach-Object {
$out.Add(
$_.Name,
$_::new()
)
}
$out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment