I’m trying to log how long a user stays in a directory. Is there any way to intercept an event whenever someone calls Set-Location?
I’m trying to log how long a user stays in a directory. Is there
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I also posted to the powershell technet forumn and got a great answer. The short story is, you can set a breakpoint on any object in powershell. With a breakpoint, you can associate a block of code (or leave out the block to pause execution). The even cooler part is that powershell provides a
pwdglobal object that represents the present working directory. You can set a breakpoint on all “write” actions on this global object.It’s basically an observer pattern or AOP. The best part is this will work for anything that changes the current directory –
cd,pushd,popd, etc. Here’s my C# cmdlet code:I’m calling a static method to track the timings. I guess I just prefer C# when possible 🙁