-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathImport-Event.ps1
62 lines (58 loc) · 1.56 KB
/
Import-Event.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
function Import-Event
{
<#
.SYNOPSIS
Imports Events
.DESCRIPTION
Imports Events from a file on disk.
.EXAMPLE
Import-Event .\Events.clixml
.LINK
Export-Event
#>
param(
# The input path. This file should be created using Export-Event
[ValidateScript({
$extension = @($_ -split '\.')[-1]
$importer = $ExecutionContext.SessionState.InvokeCommand.GetCommand(
"Import-$Extension",
"Function,Alias,Cmdlet"
)
if (-not $importer) {
throw "Import-$Extension does not exist. Cannot import .$Extension"
}
return $true
})]
[Parameter(Mandatory,ValueFromPipelineByPropertyName)]
[Alias('Fullname')]
[string]
$InputPath,
# If set, will resend events.
# Only events sent with New-Event or Send-Event will be resent.
[Alias('Replay')]
[switch]
$Resend
)
process {
if (-not (Test-Path $InputPath)) {
return
}
$extension = @($InputPath -split '\.')[-1]
$importer = $ExecutionContext.SessionState.InvokeCommand.GetCommand(
"Import-$Extension",
"Function,Alias,Cmdlet"
)
if ($resend) {
& $importer $inputPath |
& { process {
$evt = $_
if ($evt.SourceIdentifier) {
$evt | Send-Event
}
$evt
} }
} else {
& $importer $inputPath
}
}
}