Skip to content

Instantly share code, notes, and snippets.

@pkutzner
Created August 6, 2024 17:34
Show Gist options
  • Save pkutzner/4efe0fb224af439b5d1ea96bf4f075ec to your computer and use it in GitHub Desktop.
Save pkutzner/4efe0fb224af439b5d1ea96bf4f075ec to your computer and use it in GitHub Desktop.
Get list of declared functions from script
[CmdletBinding(SupportsShouldProcess)]
param (
[string]$Path
)
if (Test-Path -Path $Path) {
$Tokens = [System.Management.Automation.PSParser]::Tokenize((Get-Content -Path $Path),[ref]$null)
}
$StartLines = $Tokens | Where-Object {$_.Type -eq 'Keyword' -and $_.Content -ilike 'function'} | Select -ExpandProperty StartLine
$Tokens | Where-Object {$_.StartLine -in $StartLines -and $_.Type -eq 'CommandArgument'} | Select -ExpandProperty Content
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment