Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PowerShell Register-ObjectEvent FileSystemWatcher

Posted on 2013-01-09
1
Medium Priority
?
948 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 1500 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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

This article will help you understand what HashTables are and how to use them in PowerShell.
A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
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…

722 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