Differences

This shows you the differences between the selected revisions of the page.

2013-05-15 2013-05-28
library_from_script (martin) using Register-ObjectEvent is more powershell-like (martin)
Line 42: Line 42:
If you need to make use of these events: If you need to make use of these events:
  * Define event handling function;   * Define event handling function;
-  * Associate the event handling function with an instance of ''Session'' class using ''.add_Event'' method, where ''Event'' is a name of the event.+  * Associate the event handling function with an instance of ''Session'' class using ''[[http://technet.microsoft.com/en-us/library/hh849929.aspx|Register-ObjectEvent]]'' cmdlet.
See following code snippet: See following code snippet:
Line 64: Line 64:
# Subscribe to the event # Subscribe to the event
-$session.add_FileTransferred( { FileTransferred($_) } )+Register-ObjectEvent -inputObject $session -eventName FileTransferred ` 
 +····-Action { FileTransferred($event.sourceEventArgs) } | Out-Null
</code> </code>
-Alternatively, you can make use of ''[[http://technet.microsoft.com/en-us/library/hh849929.aspx|Register-ObjectEvent]]'' cmdlet:+Alternatively, you can make use of ''Session.add_Event'' method, where ''Event'' is a name of the event:
<code powershell> <code powershell>
# Subscribe to the event # Subscribe to the event
-Register-ObjectEvent -inputObject $session -eventName FileTransferred ` +$session.add_FileTransferred( { FileTransferred($_) } )
-····-Action { FileTransferred($event.sourceEventArgs) } | Out-Null+
</code> </code>
- 
===== Example ===== ===== Example =====

Last modified: by martin