如何在移除PowerShell脚本模块时运行自定义方法(在其自身之后进行清理)
PowerShell脚本模块在被删除时是否有办法运行某些代码 例如:如何在移除PowerShell脚本模块时运行自定义方法(在其自身之后进行清理),powershell,Powershell,PowerShell脚本模块在被删除时是否有办法运行某些代码 例如: Import-Module my-module.psm1 Remove-Module my-module # At this point I want my-module.psm1 to be notified # that it is being unloaded so it can run some clean up code. 我当前的用例是一个添加断点的模块,我希望在删除该模块时调用Remove PSBreakpoi
Import-Module my-module.psm1
Remove-Module my-module
# At this point I want my-module.psm1 to be notified
# that it is being unloaded so it can run some clean up code.
我当前的用例是一个添加断点的模块,我希望在删除该模块时调用
Remove PSBreakpoint
,这样它就不会在范围内留下混乱的内容。看看如何将这一行放入您的模块中
$MyInvocation.MyCommand.ScriptBlock.Module.OnRemove = { ## Some code }