Differences
This shows you the differences between the selected revisions of the page.
2013-09-03 | 2013-09-23 | ||
execution policy (martin) | Avoid using Register-ObjectEvent cmdlet + missing dot (martin) | ||
Line 17: | Line 17: | ||
</code> | </code> | ||
- | Note that by default, executing PowerShell scripts is disabled. To override that, you can either lift the restriction by typing using ''[[http://technet.microsoft.com/en-us/library/hh849812.aspx|Set-ExecutionPolicy]]'' cmdlet on PowerShell administrator console((Run ''powershell.exe'' as Administrator to get PowerShell console)): | + | Note that by default, executing PowerShell scripts is disabled. To override that, you can either lift the restriction by typing using ''[[http://technet.microsoft.com/en-us/library/hh849812.aspx|Set-ExecutionPolicy]]'' cmdlet on PowerShell administrator console((Run ''powershell.exe'' as Administrator to get PowerShell console.)): |
<code powershell> | <code powershell> | ||
Line 54: | Line 54: | ||
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 ''[[http://technet.microsoft.com/en-us/library/hh849929.aspx|Register-ObjectEvent]]'' cmdlet. | + | * Associate the event handling function with an instance of ''Session'' class using ''.add_Event'' method, where ''Event'' is a name of the event((Avoid using [[http://technet.microsoft.com/en-us/library/hh849929.aspx|Register-ObjectEvent]]'' cmdlet, as it introduces threading problems and possible crashes.)). |
See following code snippet: | See following code snippet: | ||
Line 75: | Line 75: | ||
... | ... | ||
- | # Subscribe to the event | ||
- | Register-ObjectEvent -inputObject $session -eventName FileTransferred ` | ||
- | -Action { FileTransferred($event.sourceEventArgs) } | Out-Null | ||
- | </code> | ||
- | |||
- | Alternatively, you can make use of ''Session.add_Event'' method, where ''Event'' is a name of the event: | ||
- | |||
- | <code powershell> | ||
# Subscribe to the event | # Subscribe to the event | ||
$session.add_FileTransferred( { FileTransferred($_) } ) | $session.add_FileTransferred( { FileTransferred($_) } ) |