Other modules Removed when PowerTab Removed

Jul 28, 2010 at 3:44 PM
Edited Jul 28, 2010 at 3:47 PM

I'm currently using PowerTab based on changeset 118313467d73.  I downloaded it last night to give it a try to see if it fixed the issue I'm seeing ( it didn't).  I'm also using PSCX Version 2.0.0.1 loaded as a module.

If I do a "Remove-Module PowerTab" some of my other modules (in particular PSCX) are removed with it (it's really annoying when the help function goes away).  Oddly it seems to add PSCX as a nested module during the import-module for PowerTab.  If I do the following it shows up.

(Get-Module PowerTab).NestedModules
ModuleType Name                      ExportedCommands
---------- ----                      ----------------
Binary     Lerch.PowerShell          Invoke-Intellisense
Manifest   PSCX                      {Invoke-AdoCommand, Set-Writable, New-MSMQueue, Write-GZip, Invoke-NullC...

I actually did a "Set-PSBreakPoint -Command 'Import-Module'" and stepped through the import of PowerTab and I found it happened when Get-Module was used in the PowerTab Module.  This is only being used to get the version of PowerTab, so I commented it out and replaced it with a static string.  At that point the problem went away.  The only thing I can think of is that there is a bug when using Get-Module inside of another module.

Get-Module is used in 2 files: PowerTab.psm1 and TabExpansionLib.ps1.  I had to remove the reference in both of them in order to get it to work.  I don't know what the best fix is, but you could manually set it to a variable in PowerTab.psm1 with something like:
$script:CurPowerTabVersion = [System.Version]'0.99.4.1'
This way it would be available everywhere else in the module without having it in multiple places.

I found a way to get some verbose output from the Get-Module command.  I'll include that at the end since it is sort of interesting as well.  It appears to "Import" all the exported commands and aliases of some of the loaded modules.  Since this would be "Imported" inside of a module, it thinks they are nested modules.  The ownership of these commands are switched to PowerTab and when it is unloaded, it unloads the nested modules and removes the commands.  Of course at this point PSCX is no longer loaded and the functions it defined are totally gone ( using help uses help.exe at this point ).

Thanks,

Stephen


# To Get more info from Get-Module Command - Set a breakpoint, run get-module, s (step into it), see interesting results.
> Set-PSBreakpoint -Command 'Get-Module'
> Get-Module -ListAvailable -debug -verbose PowerTab
Hit Command breakpoint on 'Get-Module'

Get-Module -ListAvailable -debug -verbose PowerTab
>>> s
>>>s
VERBOSE: Importing function 'Add-TabExpansion'.
VERBOSE: Importing function 'Add-TabExpansionComputer'.
VERBOSE: Importing function 'Add-TabExpansionType'.
VERBOSE: Importing function 'Export-TabExpansionConfig'.
VERBOSE: Importing function 'Export-TabExpansionDatabase'.
VERBOSE: Importing function 'Export-TabExpansionTheme'.
VERBOSE: Importing function 'Get-TabExpansion'.
VERBOSE: Importing function 'Import-TabExpansionConfig'.
VERBOSE: Importing function 'Import-TabExpansionDataBase'.
VERBOSE: Importing function 'Import-TabExpansionTheme'.
VERBOSE: Importing function 'Invoke-TabExpansion'.
VERBOSE: Importing function 'Invoke-TabExpansionEditor'.
VERBOSE: Importing function 'New-TabExpansionConfig'.
VERBOSE: Importing function 'New-TabExpansionDatabase'.
VERBOSE: Importing function 'New-TabItem'.
VERBOSE: Importing function 'Register-TabExpansion'.
VERBOSE: Importing function 'Remove-TabExpansion'.
VERBOSE: Importing function 'Remove-TabExpansionComputer'.
VERBOSE: Importing function 'Update-TabExpansionDataBase'.
VERBOSE: Importing function 'Update-TabExpansionType'.
VERBOSE: Importing function 'Update-TabExpansionWmi'.
VERBOSE: Importing variable 'PowerTabConfig'.
VERBOSE: Importing alias '?:'.
VERBOSE: Importing alias '??'.
VERBOSE: Importing alias 'ate'.
VERBOSE: Importing alias 'call'.
VERBOSE: Importing alias 'cvxml'.
VERBOSE: Importing alias 'e'.
VERBOSE: Importing alias 'ehp'.
VERBOSE: Importing alias 'ep'.
VERBOSE: Importing alias 'fdir'.
VERBOSE: Importing alias 'fhex'.
VERBOSE: Importing alias 'fxml'.
VERBOSE: Importing alias 'gcb'.
VERBOSE: Importing alias 'gpv'.
VERBOSE: Importing alias 'gte'.
VERBOSE: Importing alias 'gtn'.
VERBOSE: Importing alias 'igc'.
VERBOSE: Importing alias 'itee'.
VERBOSE: Importing alias 'ln'.
VERBOSE: Importing alias 'lorem'.
VERBOSE: Importing alias 'nho'.
VERBOSE: Importing alias 'ocb'.
VERBOSE: Importing alias 'ql'.
VERBOSE: Importing alias 'qs'.
VERBOSE: Importing alias 'Resize-Bitmap'.
VERBOSE: Importing alias 'rf'.
VERBOSE: Importing alias 'rgte'.
VERBOSE: Importing alias 'rte'.
VERBOSE: Importing alias 'rver'.
VERBOSE: Importing alias 'rvhr'.
VERBOSE: Importing alias 'rvwer'.
VERBOSE: Importing alias 'skip'.
VERBOSE: Importing alias 'sls'.
VERBOSE: Importing alias 'sro'.
VERBOSE: Importing alias 'su'.
VERBOSE: Importing alias 'swr'.
VERBOSE: Importing alias 'tail'.
VERBOSE: Importing alias 'touch'.
VERBOSE: Importing alias 'udte'.
VERBOSE: Importing cmdlet 'Add-PathVariable'.
VERBOSE: Importing cmdlet 'Clear-MSMQueue'.
VERBOSE: Importing cmdlet 'ConvertFrom-Base64'.
VERBOSE: Importing cmdlet 'ConvertTo-Base64'.
VERBOSE: Importing cmdlet 'ConvertTo-MacOs9LineEnding'.
VERBOSE: Importing cmdlet 'ConvertTo-Metric'.
VERBOSE: Importing cmdlet 'ConvertTo-UnixLineEnding'.
VERBOSE: Importing cmdlet 'ConvertTo-WindowsLineEnding'.
VERBOSE: Importing cmdlet 'Convert-Xml'.
VERBOSE: Importing cmdlet 'Disconnect-TerminalSession'.
VERBOSE: Importing cmdlet 'Expand-Archive'.
VERBOSE: Importing cmdlet 'Export-Bitmap'.
VERBOSE: Importing cmdlet 'Format-Byte'.
VERBOSE: Importing cmdlet 'Format-Hex'.
VERBOSE: Importing cmdlet 'Format-Xml'.
VERBOSE: Importing cmdlet 'Get-ADObject'.
VERBOSE: Importing cmdlet 'Get-AdoConnection'.
VERBOSE: Importing cmdlet 'Get-AdoDataProvider'.
VERBOSE: Importing cmdlet 'Get-AlternateDataStream'.
VERBOSE: Importing cmdlet 'Get-Clipboard'.
VERBOSE: Importing cmdlet 'Get-DhcpServer'.
VERBOSE: Importing cmdlet 'Get-DomainController'.
VERBOSE: Importing cmdlet 'Get-DriveInfo'.
VERBOSE: Importing cmdlet 'Get-EnvironmentBlock'.
VERBOSE: Importing cmdlet 'Get-FileTail'.
VERBOSE: Importing cmdlet 'Get-FileVersionInfo'.
VERBOSE: Importing cmdlet 'Get-ForegroundWindow'.
VERBOSE: Importing cmdlet 'Get-Hash'.
VERBOSE: Importing cmdlet 'Get-HttpResource'.
VERBOSE: Importing cmdlet 'Get-LoremIpsum'.
VERBOSE: Importing cmdlet 'Get-MountPoint'.
VERBOSE: Importing cmdlet 'Get-MSMQueue'.
VERBOSE: Importing cmdlet 'Get-OpticalDriveInfo'.
VERBOSE: Importing cmdlet 'Get-PathVariable'.
VERBOSE: Importing cmdlet 'Get-PEHeader'.
VERBOSE: Importing cmdlet 'Get-Privilege'.
VERBOSE: Importing cmdlet 'Get-PSSnapinHelp'.
VERBOSE: Importing cmdlet 'Get-ReparsePoint'.
VERBOSE: Importing cmdlet 'Get-ShortPath'.
VERBOSE: Importing cmdlet 'Get-TabExpansion'.
VERBOSE: Importing cmdlet 'Get-TerminalSession'.
VERBOSE: Importing cmdlet 'Get-TypeName'.
VERBOSE: Importing cmdlet 'Get-Uptime'.
VERBOSE: Importing cmdlet 'Import-Bitmap'.
VERBOSE: Importing cmdlet 'Invoke-AdoCommand'.
VERBOSE: Importing cmdlet 'Invoke-Apartment'.
VERBOSE: Importing cmdlet 'Join-String'.
VERBOSE: Importing cmdlet 'New-Hardlink'.
VERBOSE: Importing cmdlet 'New-Junction'.
VERBOSE: Importing cmdlet 'New-MSMQueue'.
VERBOSE: Importing cmdlet 'New-Shortcut'.
VERBOSE: Importing cmdlet 'New-Symlink'.
VERBOSE: Importing cmdlet 'Out-Clipboard'.
VERBOSE: Importing cmdlet 'Ping-Host'.
VERBOSE: Importing cmdlet 'Pop-EnvironmentBlock'.
VERBOSE: Importing cmdlet 'Push-EnvironmentBlock'.
VERBOSE: Importing cmdlet 'Read-Archive'.
VERBOSE: Importing cmdlet 'Receive-MSMQueue'.
VERBOSE: Importing cmdlet 'Remove-AlternateDataStream'.
VERBOSE: Importing cmdlet 'Remove-MountPoint'.
VERBOSE: Importing cmdlet 'Remove-ReparsePoint'.
VERBOSE: Importing cmdlet 'Resolve-Host'.
VERBOSE: Importing cmdlet 'Send-MSMQueue'.
VERBOSE: Importing cmdlet 'Send-SmtpMail'.
VERBOSE: Importing cmdlet 'Set-BitmapSize'.
VERBOSE: Importing cmdlet 'Set-Clipboard'.
VERBOSE: Importing cmdlet 'Set-FileTime'.
VERBOSE: Importing cmdlet 'Set-ForegroundWindow'.
VERBOSE: Importing cmdlet 'Set-PathVariable'.
VERBOSE: Importing cmdlet 'Set-Privilege'.
VERBOSE: Importing cmdlet 'Set-VolumeLabel'.
VERBOSE: Importing cmdlet 'Skip-Object'.
VERBOSE: Importing cmdlet 'Split-String'.
VERBOSE: Importing cmdlet 'Start-TabExpansion'.
VERBOSE: Importing cmdlet 'Stop-TerminalSession'.
VERBOSE: Importing cmdlet 'Test-AlternateDataStream'.
VERBOSE: Importing cmdlet 'Test-Assembly'.
VERBOSE: Importing cmdlet 'Test-MSMQueue'.
VERBOSE: Importing cmdlet 'Test-Script'.
VERBOSE: Importing cmdlet 'Test-UserGroupMembership'.
VERBOSE: Importing cmdlet 'Test-Xml'.
VERBOSE: Importing cmdlet 'Unblock-File'.
VERBOSE: Importing cmdlet 'Write-BZip2'.
VERBOSE: Importing cmdlet 'Write-Clipboard'.
VERBOSE: Importing cmdlet 'Write-GZip'.
VERBOSE: Importing cmdlet 'Write-Tar'.
VERBOSE: Importing cmdlet 'Write-Zip'.
VERBOSE: Importing function 'Add-DirectoryLength'.
VERBOSE: Importing function 'Add-ShortPath'.
VERBOSE: Importing function 'Dismount-VHD'.
VERBOSE: Importing function 'Edit-File'.
VERBOSE: Importing function 'Edit-HostProfile'.
VERBOSE: Importing function 'Edit-Profile'.
VERBOSE: Importing function 'Enable-OpenPowerShellHere'.
VERBOSE: Importing function 'Get-Help'.
VERBOSE: Importing function 'Get-PropertyValue'.
VERBOSE: Importing function 'Get-ScreenCss'.
VERBOSE: Importing function 'Get-ScreenHtml'.
VERBOSE: Importing function 'Get-ViewDefinition'.
VERBOSE: Importing function 'help'.
VERBOSE: Importing function 'Invoke-BatchFile'.
VERBOSE: Importing function 'Invoke-Elevated'.
VERBOSE: Importing function 'Invoke-GC'.
VERBOSE: Importing function 'Invoke-Method'.
VERBOSE: Importing function 'Invoke-NullCoalescing'.
VERBOSE: Importing function 'Invoke-Reflector'.
VERBOSE: Importing function 'Invoke-Ternary'.
VERBOSE: Importing function 'less'.
VERBOSE: Importing function 'Mount-VHD'.
VERBOSE: Importing function 'New-HashObject'.
VERBOSE: Importing function 'Out-Speech'.
VERBOSE: Importing function 'QuoteList'.
VERBOSE: Importing function 'QuoteString'.
VERBOSE: Importing function 'Resolve-ErrorRecord'.
VERBOSE: Importing function 'Resolve-HResult'.
VERBOSE: Importing function 'Resolve-WindowsError'.
VERBOSE: Importing function 'Set-LocationEx'.
VERBOSE: Importing function 'Set-ReadOnly'.
VERBOSE: Importing function 'Set-Writable'.
VERBOSE: Importing function 'Show-Tree'.
VERBOSE: Importing function 'Stop-RemoteProcess'.
VERBOSE: Importing alias '?:'.
VERBOSE: Importing alias '??'.
VERBOSE: Importing alias 'call'.
VERBOSE: Importing alias 'cvxml'.
VERBOSE: Importing alias 'e'.
VERBOSE: Importing alias 'ehp'.
VERBOSE: Importing alias 'ep'.
VERBOSE: Importing alias 'fhex'.
VERBOSE: Importing alias 'fxml'.
VERBOSE: Importing alias 'gcb'.
VERBOSE: Importing alias 'gpv'.
VERBOSE: Importing alias 'gtn'.
VERBOSE: Importing alias 'igc'.
VERBOSE: Importing alias 'ln'.
VERBOSE: Importing alias 'lorem'.
VERBOSE: Importing alias 'nho'.
VERBOSE: Importing alias 'ocb'.
VERBOSE: Importing alias 'ql'.
VERBOSE: Importing alias 'qs'.
VERBOSE: Importing alias 'Resize-Bitmap'.
VERBOSE: Importing alias 'rf'.
VERBOSE: Importing alias 'rver'.
VERBOSE: Importing alias 'rvhr'.
VERBOSE: Importing alias 'rvwer'.
VERBOSE: Importing alias 'skip'.
VERBOSE: Importing alias 'sls'.
VERBOSE: Importing alias 'sro'.
VERBOSE: Importing alias 'su'.
VERBOSE: Importing alias 'swr'.
VERBOSE: Importing alias 'tail'.
VERBOSE: Importing alias 'touch'.
VERBOSE: Importing function 'Find-File'.
VERBOSE: Importing alias 'fdir'.

ModuleType Name                      ExportedCommands
---------- ----                      ----------------
Manifest   PowerTab                  {Add-TabExpansion, Get-TabExpansion, New-TabItem, Add-TabExpansionType, ...

Jul 28, 2010 at 10:41 PM

It looks like this can be resolved by using the following in both locations.

$CurVersion = (Test-ModuleManifest -Path "$PSScriptRoot\PowerTab.psd1").Version

Hopefully this help.

Stephen Mills

Coordinator
Jul 29, 2010 at 3:20 AM
Wow, very nasty bug. Thank you for your investigation. It seems that this happens for all modules loaded before PowerTab. I think this is a bug in PowerShell, so I will have to work around it. Jaykul had given me that code so I wouldn't have to parse the manifest file myself.
Coordinator
Jul 29, 2010 at 3:33 AM
I have created an updated release with a fix. Thanks.
Jul 29, 2010 at 6:38 AM

Thanks for the fix.  It looks good.