Skip to content

Instantly share code, notes, and snippets.

@idavis
Created June 9, 2015 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save idavis/293022f2ebe30f726673 to your computer and use it in GitHub Desktop.
Save idavis/293022f2ebe30f726673 to your computer and use it in GitHub Desktop.
Replacing the private functionality of loaded module
$module = New-Module -Name "monkey" -ScriptBlock {
function Get-Stuff {
return GetStuffPrivate
}
function GetStuffPrivate {
5
}
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