Skip to content

Instantly share code, notes, and snippets.

@pandieme
Created April 4, 2022 10:01
Show Gist options
  • Save pandieme/7d4ce322df3821ae75a1fb5f3db49db9 to your computer and use it in GitHub Desktop.
Save pandieme/7d4ce322df3821ae75a1fb5f3db49db9 to your computer and use it in GitHub Desktop.
function Import-ModuleFunctions(
[Parameter()]
[array]
$Roots = @(
"$PSScriptRoot/public"
"$PSScriptRoot/private"
),
[Parameter()]
[switch]
$All
) {
<#
.SYNOPSIS
Import module functions
#>
$PublicFunctions = $()
$Roots | ForEach-Object {
if (Test-Path -Path $_) {
Get-ChildItem -Path $_ -Filter "*.ps1" -Recurse | `
ForEach-Object {
if ($_ -match 'public') {
$PublicFunctions += $_.BaseName
}
elseif ($All) {
$PublicFunctions += $_.BaseName
}
$AllFunctions += $_.BaseName
. $_.FullName
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment