silktco.psm1
|
#Get public and private function definition files. $PublicPath = Join-Path $PSScriptRoot 'public' $PrivatePath = Join-Path $PSScriptRoot 'private' Write-Verbose "Module root: $PSScriptRoot" -Verbose Write-Verbose "Searching for functions in: $PublicPath" -Verbose Write-Verbose "Searching for functions in: $PrivatePath" -Verbose if (-not (Test-Path $PublicPath)) { Write-Warning "Public path does not exist: $PublicPath" } if (-not (Test-Path $PrivatePath)) { Write-Warning "Private path does not exist: $PrivatePath" } $Public = @( Get-ChildItem -Path $PublicPath -Filter '*.ps1' -ErrorAction SilentlyContinue -Recurse ) $Private = @( Get-ChildItem -Path $PrivatePath -Filter '*.ps1' -ErrorAction SilentlyContinue -Recurse ) Write-Verbose "Found $($Public.Count) public functions" -Verbose Write-Verbose "Found $($Private.Count) private functions" -Verbose $allpublic = @($Public) $num = 0 Foreach($import in @($allpublic + $Private)) { Try { $functionName = $import.basename Write-Verbose "-> importing - $functionName -" -Verbose . $import.fullname } Catch { Write-Error -Message "Failed to import function $($import.fullname): $_" } $num++ } Export-ModuleMember -Function $allpublic.Basename -alias * Write-Verbose "--- Loaded $num functions ---" -Verbose |