Solved

PowerShell Register-ObjectEvent FileSystemWatcher

Posted on 2013-01-09
1
898 Views
Last Modified: 2013-01-11
Hello,
I'm trying to utilize the .NET FileSystemWatcher to monitor a directory for changes. My script works but I've noticed the registered events are lost at log out. Is there a way to make these registered events persist through logout/reboot?
0
Comment
Question by:HumanScaleDev
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 38760677
It is an expected behavior. The event subscription will only available if the PowerShell is running. When you close the PS console, the event registration will be cleared.

You may turn on automatic logon and run the PowerShell script as a logon script with -noexit. I have never tried it but if it is an option for you then you can check it out.. :-)
Set objShell = CreateObject("Wscript.Shell")
objShell.Run("powershell.exe -noexit c:\scripts\test.ps1")

Open in new window

Ref :http://technet.microsoft.com/en-us/library/ee176949.aspx
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Synchronize a new Active Directory domain with an existing Office 365 tenant
This article will help you understand what HashTables are and how to use them in PowerShell.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the adminiā€¦

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question