How does PowerShell detect which module to load automatically when I use a cmdlet from a module that isn’t currently loaded?

PS C:Windowssystem32> Get-Module ModuleType Version Name ExportedCommands ---------- ------- ---- ---------------- Manifest 3.1.0.0 Microsoft.PowerShell.Management {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Con... Manifest 3.1.0.0 Microsoft.PowerShell.Utility {Add-Member, Add-Type, Clear-Variable, Compare-Object...} Script 1.2 PSReadline {Get-PSReadlineKeyHandler, Get-PSReadlineOption, Remove-PS... PS C:Windowssystem32> $(Get-NetIPAddress -AddressFamily IPv4)[0].IPAddress 192.168.2.46 PS C:Windowssystem32> Get-Module ModuleType Version Name ExportedCommands ---------- ------- ---- ---------------- Manifest 3.1.0.0 Microsoft.PowerShell.Management {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Con... Manifest 3.1.0.0 Microsoft.PowerShell.Utility {Add-Member, Add-Type, Clear-Variable, Compare-Object...} Manifest 1.0.0.0 NetTCPIP {Find-NetRoute, Get-NetCompartment, Get-NetIPAddress, Get-... Script 1.2 PSReadline {Get-PSReadlineKeyHandler, Get-PSReadlineOption, Remove-PS... 

Larger question – Is there something like PSScriptAnalyzer that can analyze a PowerShell Script and tell me all of the Modules (already installed on the system) that would be needed to run it?

EDIT:

Given an unknown cmdlet, it couldn’t possible dynamically search all of the Module Manifests under all of the $env:PSModulePath paths…right? Or maybe it does? Is there a cache of all manifest info somewhere such that it doesn’t need to inspect every .psd1 file everytime it encounters an unknown cmdlet?

submitted by /u/fourierswager
[link] [comments]

Leave a Reply