Replacing the private functionality of loaded module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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