command line - PowerShell: Can you hook or intercept PowerShell execution of external applications? -
I want to do some housekeeping before performing any external console applications (some environment wors settings).
In my web research, it seems that NotifyBeginApplication () notification in $ host can be a trick Unfortunately, I can not understand how to do this.
Here's what I want to do ...
$ host = $ host | `Add-member-force -pass -mem scriptmethod NotifyBeginApplication` {$ env: _startTime = [datetime] :: now; $ Env: _line = $ myInvocation.Line}
This does not work as the host is stable and it may be wrong.
This document is capable of finding states that before executing any "legacy" console application, this function is called, but another blog entry says that it is only available to console applications , Who do not have an I / O redirection.
So what is the right way to do this? If so, how do I override the function?
If not, how can this be done?
The only option I have seen that can work is to fully implement a custom PSHost, it seems to be possible with the existing available source code, but more than anything I want to try.
I also agree with you (unfortunate) that you have your own custom host Will need to be created.
You can easily create additional runpacks through scripting, but this method is your current running host (default console).
Comments
Post a Comment