Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在移除PowerShell脚本模块时运行自定义方法(在其自身之后进行清理)_Powershell - Fatal编程技术网

如何在移除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

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 PSBreakpoint
,这样它就不会在范围内留下混乱的内容。

看看如何将这一行放入您的模块中

$MyInvocation.MyCommand.ScriptBlock.Module.OnRemove = { ## Some code }