| | | 1 | | <# |
| | | 2 | | .SYNOPSIS |
| | | 3 | | Returns modules imported by the user session. |
| | | 4 | | |
| | | 5 | | .DESCRIPTION |
| | | 6 | | Filters the list of currently loaded modules to exclude built-in PowerShell |
| | | 7 | | modules, Visual Studio Code host modules and Microsoft.PowerShell.* modules. |
| | | 8 | | The result represents modules explicitly imported by the user or scripts. |
| | | 9 | | #> |
| | | 10 | | function Get-KrUserImportedModule { |
| | | 11 | | [CmdletBinding()] |
| | | 12 | | [OutputType([System.Management.Automation.PSModuleInfo])] |
| | | 13 | | param() |
| | | 14 | | |
| | | 15 | | # ----- constants ---------------------------------------------------------- |
| | 0 | 16 | | $inboxRoot = [IO.Path]::GetFullPath( (Join-Path $PSHOME 'Modules') ) |
| | | 17 | | |
| | | 18 | | # regex fragment that matches “…\.vscode\extensions\ms-vscode.powershell…” |
| | 0 | 19 | | $vsCodeRegex = [Regex]::Escape( |
| | | 20 | | [IO.Path]::Combine('.vscode', 'extensions', 'ms-vscode.powershell') |
| | | 21 | | ) -replace '\\\\', '[\\/]' # make path-separator agnostic |
| | | 22 | | # ------------------------------------------------------------------------- |
| | | 23 | | |
| | 0 | 24 | | Get-Module | Where-Object { |
| | 0 | 25 | | $path = [IO.Path]::GetFullPath($_.ModuleBase) |
| | | 26 | | |
| | 0 | 27 | | $isInbox = $path.StartsWith($inboxRoot, |
| | | 28 | | $IsWindows ? 'OrdinalIgnoreCase' : 'Ordinal') |
| | 0 | 29 | | $isVSCode = $path -match $vsCodeRegex |
| | 0 | 30 | | $isMSPSSpace = $_.Name -like 'Microsoft.PowerShell.*' |
| | | 31 | | |
| | 0 | 32 | | -not ($isInbox -or $isVSCode -or $isMSPSSpace) |
| | | 33 | | } |
| | | 34 | | } |
| | | 35 | | |