Dienstag, 30. März 2010

PowerShell modules are funny guys (II)

Here I'll focus on the irritating feature. The following script creates 2 modules in your user modul folder.
The second module imports the first module.

Import the first module, then the second. Both modules are imported.
Now remove the second module (that which imports the other too) and both are gone.

$modpath1 = ($env:PSModulepath -split ';')[0]            
mkdir $modpath1\submod -force
mkdir $modpath1\testmod -force



@'
$script:state_s = 0

function Get-State
{
return $script:state_s
}

function Set-State ($x)
{
$script:state_s = ($x)
}
'@
> "$modpath1\submod\submod.psm1"


@'
Import-Module submod.psm1


function Get-StateY
{
return Get-State
}

function Set-StateY ($x)
{
Set-State $x
}
'@
> "$modpath1\testmod\testmod.psm1"

ipmo submod
ipmo testmod
Write-host '------------'
gmo
Write-host '------------'
rmo testmod
gmo


Do you agree, that is to be called a bug?

Bernd

Keine Kommentare:

Kommentar veröffentlichen