Skip to content

Instantly share code, notes, and snippets.

@sowderca
Created January 18, 2022 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sowderca/83c8e44434a2d9dea33eef96fb4a0b76 to your computer and use it in GitHub Desktop.
Save sowderca/83c8e44434a2d9dea33eef96fb4a0b76 to your computer and use it in GitHub Desktop.
Exclude based upon attribute
Get-ChildItem -Path './src' -Filter '*.ps1' -File -Recurse | ForEach-Object {
$functions = (Get-Command $_.FullName).ScriptBlock.Ast.FindAll( { $args[0] -is [System.Management.Automation.Language.FunctionDefinitionAst] }, $false);
foreach ($func in $functions) {
[ScriptBlock] $code = [ScriptBlock]::Create("function tmp-$($func.Name) $($func.Body)");
New-Module -Name 'tmp-mod' -ScriptBlock $code | Out-Null;
[PSCustomObject] @{
File = $_.Name;
Function = $func.Name;
Attributes = (Get-Command -Name "tmp-$($func.Name)").ScriptBlock.Attributes | % { ${PSItem}?.TypeId?.Name }
};
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment