Sonntag, 15. November 2009

Manage Modules The ISE Way

Hello again

Last month we got a lot of modules to try. Example given PowerShellPack or BSonPosh Powershell Module.

Of corse you do not want to add all the modules you find to your profile.
To be honest isepack is the only module I load in my profile.
I just added a smal script to my personal toolbox of ISE Add-On Extensions.

It adds and removes modules, list the currently loaded and shows the files of a module.

Pleae be warned, not all modules are writen to be removed, e.g. ispack does not remove its menus, when removed. But you have a starting point to play with.

And thanks again to James Brundage, whoes Copy-ColoredHTML (it's in the ISEpack module of the PowerShellPack) makes posting PowerShell code so easy.

function Update-ModuleMenu()            
{
$all_modules = get-module -list
$loaded_modules = get-module

$remove_items = @{}
$loaded_modules | % {
$name = $_.name
$remove_items[$_.name] = "Remove-module $name; Update-ModuleMenu"
}

$add_items = @{}
$all_modules | ? {! ($loaded_modules -contains $_ )} |
% {
$name = $_.name
$add_items[$_.name] = "Import-module $name; Update-ModuleMenu"

$list_items = @{}
$all_modules | % {
$list_items[$_.name] = "gci (split-path (get-module $_ -list).Path) | select Name"
}

$items = @{
" loaded" = {Get-Module | Sort-object | select name, path | fl}
" add" = $add_items
" remove" = $remove_items
"files" = $list_items
}
}

#$items

Add-IseMenu -name 'Module' $items
}


Update-ModuleMenu

Keine Kommentare:

Kommentar veröffentlichen