# encoding: ascii
# api: powershell
# title: Enter-Module.ps1
# description: From Windows PowerShell Cookbook (O’Reilly) by Lee Holmes
# version: 0.1
# type: module
# author: Lee Holmes
# license: CC0
# x-poshcode-id: 2142
# x-archived: 2016-05-17T13:37:38
# x-published: 2011-09-09T21:40:00
#
#
##############################################################################
##
## Enter-Module
##
## From Windows PowerShell Cookbook (O'Reilly)
## by Lee Holmes (http://www.leeholmes.com/guide)
##
##############################################################################
<#
.SYNOPSIS
Lets you examine internal module state and functions by executing user
input in the scope of the supplied module.
.EXAMPLE
PS >Import-Module PersistentState
PS >Get-Module PersistentState
ModuleType Name ExportedCommands
---------- ---- ----------------
Script PersistentState {Set-Memory, Get-Memory}
PS >"Hello World" | Set-Memory
PS >$m = Get-Module PersistentState
PS >Enter-Module $m
PersistentState: dir variable:\mem*
Name Value
---- -----
memory {Hello World}
PersistentState: exit
PS >
#>
param(
## The module to examine
[System.Management.Automation.PSModuleInfo] $Module
)
Set-StrictMode -Version Latest
$userInput = Read-Host $($module.Name)
while($userInput -ne "exit")
{
$scriptblock = [ScriptBlock]::Create($userInput)
& $module $scriptblock
$userInput = Read-Host $($module.Name)
}