powershell - Powershell配置文件 “on exit”事件?

标签 powershell

我正在寻找一种在PowerShell session 退出时自动执行一些清理任务的方法。因此,例如,在我的配置文件中,我启动了一个进程,该进程需要在后台运行,以执行很多任务,并且我想在关闭控制台时自动关闭该进程。

在关闭 session 时,PowerShell是否有某些功能像在显示提示时使用prompt一样自动调用?

最佳答案

您可以使用 Register-EngineEvent cmdlet将事件处理程序附加到Exiting事件:

Register-EngineEvent PowerShell.Exiting -Action { ... }
但是请注意,如果您关闭控制台窗口,则不会触发此事件。

关于powershell - Powershell配置文件 “on exit”事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2436510/

相关文章:

powershell - 如何在 PowerShell 中查询 .pdb 文件?

powershell - 找不到 Azure Get-AzureRmMlService Powershell

powershell - 需要通过带有调用命令的 powershell 远程访问第二个跃点

powershell - 如何通过Powershell启用Azure Cosmos DB预览功能(聚合管道和Mongodbv3.4)?

powershell - 我如何判断驱动器是 DVD 驱动器还是虚拟驱动器,测试路径不够?

Powershell:我需要清理一组 csv 文件,在导入前必须去的 header 上方有不一致数量的垃圾行

powershell - 类型 "bind": bind source path does not exist when trying to run container on Docker for Windows 的安装配置无效

powershell - PowerShell获取网络计算机列表

json - Powershell ConvertTo-Json键小写

powershell - PowerShell 上的提升/Sudo