forked from StartAutomating/Eventful
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get-EventHandler.ps1
43 lines (37 loc) · 1.31 KB
/
Get-EventHandler.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
function Get-EventHandler
{
<#
.Synopsis
Gets Event Handlers
.Description
Gets files that act as Event Handlers.
These files can be named a few ways:
* On_[EventName].ps1 / [EventName].handler.ps1 (These handle a single event)
* [Name].handlers.ps1 / [Name].events.ps1 (These handle multiple events)
#>
param(
# The path to the handler file(s)
[Parameter(ValueFromPipelineByPropertyName)]
[string[]]
$HandlerPath
)
begin {
$namingConvention = "On_(?<Name>.+)\.ps1$", "(?<Name>.+)\.handler\.ps1$", "(?<Name>.+)\.handlers\.ps1$", "(?<Name>.+)\.events\.ps1$"
$namingConvention = "(?>$($namingConvention -join '|'))"
}
process {
if (-not $HandlerPath) { # If we don't have a handler path
$HandlerPath = $PWD # assume the current directory
}
foreach ($path in $HandlerPath) {
Get-ChildItem -Path $path |
Where-Object Name -Match $namingConvention |
ForEach-Object {
$cmd = $ExecutionContext.InvokeCommand.GetCommand($_.FullName, 'ExternalScript')
$cmd.pstypenames.clear()
$cmd.pstypenames.add('Eventful.EventHandler')
$cmd
}
}
}
}