Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions developer/cmdlet/events01-sample.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@ caps.latest.revision: 10
---
# Events01 Sample

This sample shows how to create a cmdlet that allows the user to register for events that are raised by [System.IO.Filesystemwatcher](/dotnet/api/System.IO.FileSystemWatcher). With this cmdlet, users can register an action to execute when a file is created under a specific directory. This sample derives from the [Microsoft.PowerShell.Commands.Objecteventregistrationbase](/dotnet/api/Microsoft.PowerShell.Commands.ObjectEventRegistrationBase) base class.
This sample shows how to create a cmdlet that allows the user to register for events that are raised by [System.IO.FileSystemWatcher](/dotnet/api/System.IO.FileSystemWatcher).
With this cmdlet, users can register an action to execute when a file is created under a specific directory.
This sample derives from the [Microsoft.PowerShell.Commands.ObjectEventRegistrationBase](/dotnet/api/Microsoft.PowerShell.Commands.ObjectEventRegistrationBase) base class.

## How to build the sample by using Visual Studio.

1. With the Windows PowerShell 2.0 SDK installed, navigate to the Events01 folder. The default location is C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0\Samples\sysmgmt\WindowsPowerShell\csharp\Events01.
1. With the Windows PowerShell 2.0 SDK installed, navigate to the Events01 folder.
The default location is `C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0\Samples\sysmgmt\WindowsPowerShell\csharp\Events01`.

2. Double-click the icon for the solution (.sln) file. This opens the sample project in Microsoft Visual Studio.
2. Double-click the icon for the solution (.sln) file.
This opens the sample project in Microsoft Visual Studio.

3. In the **Build** menu, select **Build Solution**.

The library for the sample will be built in the default \bin or \bin\debug folders.
The library for the sample will be built in the default `\bin` or `\bin\debug` folders.

### How to run the sample

Expand Down Expand Up @@ -72,11 +75,14 @@ This sample requires Windows PowerShell 2.0.

This sample demonstrates the following.

- How to write a cmdlet for event registration. The cmdlet derives from the [Microsoft.PowerShell.Commands.Objecteventregistrationbase](/dotnet/api/Microsoft.PowerShell.Commands.ObjectEventRegistrationBase) class, which provides support for parameters common to the Register-*Event cmdlets. Cmdlets that are derived from [Microsoft.PowerShell.Commands.Objecteventregistrationbase](/dotnet/api/Microsoft.PowerShell.Commands.ObjectEventRegistrationBase) need only to define their particular parameters and override the `GetSourceObject` and `GetSourceObjectEventName` abstract methods.
### How to write a cmdlet for event registration

The cmdlet derives from the [Microsoft.PowerShell.Commands.ObjectEventRegistrationBase](/dotnet/api/Microsoft.PowerShell.Commands.ObjectEventRegistrationBase) class, which provides support for parameters common to the `Register-*Event` cmdlets.
Cmdlets that are derived from [Microsoft.PowerShell.Commands.ObjectEventRegistrationBase](/dotnet/api/Microsoft.PowerShell.Commands.ObjectEventRegistrationBase) need only to define their particular parameters and override the `GetSourceObject` and `GetSourceObjectEventName` abstract methods.

## Example

This sample shows how to register for events raised by [System.IO.FileSystemWatcher](https://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher\(v=vs.110\).aspx).
This sample shows how to register for events raised by [System.IO.FileSystemWatcher](/dotnet/api/System.IO.FileSystemWatcher).

```csharp
namespace Sample
Expand Down Expand Up @@ -177,4 +183,4 @@ namespace Sample

## See Also

[Writing a Windows PowerShell Cmdlet](./writing-a-windows-powershell-cmdlet.md)
[Writing a Windows PowerShell Cmdlet](writing-a-windows-powershell-cmdlet.md)