Created
August 6, 2024 17:34
-
-
Save pkutzner/4efe0fb224af439b5d1ea96bf4f075ec to your computer and use it in GitHub Desktop.
Get list of declared functions from script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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