Bug with Modules can cause PSCX to be Removed

Topics: Developer Forum, User Forum
Aug 6, 2010 at 3:19 PM
Edited Aug 6, 2010 at 3:34 PM

There is a bug with Modules that can cause PSCX to be removed incorrectly ( basically leaves it Imported, but corrupted ).

This can happen if:

-A module uses a Module Manifest and it uses the ModuleToProcess Section

-Or a module uses Import-Module ( including importing Pscx)

-Or a module uses "Get-Module -ListAvailable" during the Import-Module process (.psm1)

-One of the above is true and "Get-Module -ListAvailable" is called anywhere - doesn't matter if a user uses it or if in a script or module function

-One of the above is true and the user uses "Remove-Module" and removes a module

I've seen issues at work when an exported variable/module scoped variable would occasionally get set to $null. I finally saw it where I could reproduce it when working with Powertab ( powertab.codeplex.com ). If I removed Powertab, PSCX (Version ) would go away as well. JasonMArcher modified the currently released version a few days ago to prevent it from being as bad, now if you remove Powertab pscx doesn't go away, but just using "Get-Module -ListAvailable" will cause all module scoped or exported variables to be set to $null. Not sure how much that effects Pscx, but it sure messes up lots of things for me.

If interested in this bug, please take the time to go to Connect.Microsoft.com and vote on it. JasonMArcher was really quick and created feedback for it the same day I let him know about it. It's one of the nastier bugs I've seen in PowerShell and there isn't an easy work around for it either.


Last Powertab version with issue with Removing PSCX



Aug 6, 2010 at 3:40 PM

Here's a simple example of what I've talking about.

Create a module called TestMod.  It should contain the following:

Get-Module -ListAvailable | Out-Null

Then run Powershell -NoProfile

Followed by the following:

Import-Module Pscx
Get-Command -Module Pscx | Measure-Object
Import-Module TestMod
Get-Command -Module Pscx | Measure-Object
Remove-Module TestMod
Get-Command -Module Pscx | Measure-Object

At the end it returns a count of 0 for commands in the module Pscx.  Pscx is actually no longer loaded in this case as well.


Aug 9, 2010 at 1:21 AM

Yeah I saw this bug makes the rounds last week on the PowerShell MVP list server.  Pretty nasty PowerShell bug. Unfortunately the work-around - never use ipmo inside a module - would require a significant change to PSCX.  We'll monitor the situation.  Hopefully this is something that the PowerShell team can fix for Windows 7 SP1 (kind of doubt it though).