gpt4 book ai didi

powershell - 有没有办法 Hook 内部 PowerShell 函数事件?

转载 作者:行者123 更新时间:2023-12-02 23:16:47 25 4
gpt4 key购买 nike

有没有办法 Hook 内部 PowerShell 函数事件?特别是在调用开始、完成或出错时向 Copy-Item 函数添加代码。我知道我可以重写该函数,但我试图避免重写该代码。
您甚至如何获得可用于 Copy-Item 的事件?

最佳答案

看看proxy functions :

$MetaData = New-Object System.Management.Automation.CommandMetaData (Get-Command  Copy-Item)
[System.Management.Automation.ProxyCommand]::Create($MetaData)
当然,它确实需要编写一些代码,但它肯定比重新编译核心 DLL 更容易。

关于powershell - 有没有办法 Hook 内部 PowerShell 函数事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64395232/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com