powershell - Register-ObjectEvent Event Subscription Uptime -


we have data dump come external entity on daily basis. once receive file, object event listener triggers, moves file 2 separate locations (one live, 1 backup) , calls ms sql stored procedure import file database.

the process , script seem function fine. file moves, , sql executed. however, every morning when check see if triggered, nothing triggered. check event-subscribers calling get-eventsubscriber , there no listeners registered. once register listeners , move file input location, runs fine.

i understand event subscriptions not persist through reboots, how long stay open? possible closing them? or time out?

$watchfolder = "\\server\c$\path\to\inbound\" $filter = "*.txt"  $fsw = new-object io.filesystemwatcher $watchfolder, $filter -property @{     includesubdirectories = $false     notifyfilter = [io.notifyfilters]'filename, lastwrite' }  $oncreated = register-objectevent $fsw created -sourceidentifier filemonitor -action {     $filepath = $event.sourceeventargs.fullpath     $filename = $event.sourceeventargs.name     write-host "source file: $filename"     $success = copyfile($filename, $filepath) #custom function copy file multiple destinations      if ($success) {         write-host "starting sql_job_name job"         set-location sqlserver:\sql\server\default\databases\msdb\         $execute_import = "exec dbo.sp_start_job n'sql_job_name';"         invoke-sqlcmd -suppressprovidercontextwarning -query $execute_import     } else {         write-host "something failed along way: `r`n"     } } 

as silly seems, learned here calling register-objectevent if powershell process closed, objectevent unregistered.

because nature of project required have always-on file listener, decided powershell not correct implementation us.

instead implemented windows service using .net libraries, same used here in powershell.

thanks petseral prompt answer.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -