根据我的评论详细说明。所以,在PowerShell中,也许是这样的......
# Put this in your profile (ISE/PowerShell/VSCode)
$AutomaticModules = Get-Module
$AutomaticModules
# Results
<#
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Binary 1.0.0.0 CimCmdlets {Export-BinaryMiLog, ...
Script 1.1.0 ClassExplorer {Find-Member, Find-Na...
...
#>
# Get only modules loaded during the session
Compare-Object -ReferenceObject (Get-Module) -DifferenceObject $AutomaticModules -Property Name -PassThru |
Where -Property Name -ne 'AutomaticModules'
# Results
<#
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Manifest 3.0.0.0 Microsoft.PowerShell.Security {ConvertFrom-SecureString, ...
Manifest 3.0.0.0 Microsoft.WSMan.Management {Connect-WSMan, Disable-WSMa...
#>
Import-Module -Name IsePester
Compare-Object -ReferenceObject (Get-Module) -DifferenceObject $AutomaticModules -Property Name -PassThru |
Where -Property Name -ne 'AutomaticModules'
# Results
<#
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 0.0 IsePester {Add-PesterMenu, Get-PesterM...
Manifest 3.0.0.0 Microsoft.PowerShell.Security {ConvertFrom-SecureString, C...
Manifest 3.0.0.0 Microsoft.WSMan.Management {Connect-WSMan, Disable-WSMa...
#>
所以,作为一个函数:
function Get-SessionModule
{
Param
(
[String]$ModuleName
)
(Compare-Object -ReferenceObject (Get-Module) -DifferenceObject $AutomaticVModules -Property Name -PassThru |
Where -Property Name -ne 'AutomaticVModules') -Match $ModuleName
}
Get-SessionModule -ModuleName IsePester
# Results
<#
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 0.0 IsePester {Add-PesterMenu, Ge...
#>