FunctionModuleMap Skill
Overview
The FunctionModuleMap in Start-SystemOptimizer.ps1 maps function names to their source modules. This enables:
- •Auto-reload of missing modules
- •Module identification for error messages
- •Dynamic function discovery
Location
powershell
# In Start-SystemOptimizer.ps1
$script:FunctionModuleMap = @{
'Function-Name' = 'ModuleName'
}
When to Update
Add entries when:
- •Creating new exported functions
- •Renaming existing functions
- •Creating new modules
Entry Format
powershell
'Function-Name' = 'ModuleName'
Note: ModuleName is the base name without .psm1 extension.
Categories
Organize entries by category:
powershell
# Core Modules 'Run-AllOptimizations' = 'Core' # System Modules 'Disable-Telemetry' = 'Telemetry' 'Show-ServicesMenu' = 'Services' # Utility Modules 'Get-WifiPasswords' = 'Utilities'
Complete Update Checklist
When adding a new function:
- • Add function to module's Export-ModuleMember
- • Add entry to FunctionModuleMap
- • Add menu item (if user-facing)
- • Add to switch statement (if menu item)
- • Update module documentation header
Example
Adding a new Network function:
powershell
# In Network.psm1
function Get-NetworkStatus { }
Export-ModuleMember -Function @(
'Get-NetworkStatus' # Add to exports
)
# In Start-SystemOptimizer.ps1
$script:FunctionModuleMap = @{
# Network
'Get-NetworkStatus' = 'Network' # Add to map
}
Auto-Reload Behavior
When Invoke-OptFunction can't find a function:
- •Looks up module name in FunctionModuleMap
- •Attempts to reload that module
- •If module missing, offers to download from GitHub
- •Retries function call after reload
Troubleshooting
If auto-reload fails:
- •Verify function name spelling matches
- •Check module name is correct
- •Ensure function is exported in module
- •Verify module file exists in modules/ directory