Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Replacing the private functionality of loaded module
$module = New-Module -Name "monkey" -ScriptBlock {
function Get-Stuff {
return GetStuffPrivate
function GetStuffPrivate {
Export-ModuleMember Get-Stuff
Import-Module $module # you can also just use $module = Get-Module "someName"
Get-Stuff # returns 5
# DoStuffPrivate # this is private, can't call it
. $module {function GetStuffPrivate { "tehehe" }}
Get-Stuff # returns "tehehe"
Remove-Module [m]onkey
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment