-
Notifications
You must be signed in to change notification settings - Fork 3
/
Convert-EmlFile.ps1
45 lines (35 loc) · 1.07 KB
/
Convert-EmlFile.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
function Convert-EmlFile
{
<#
.SYNOPSIS
Function will parse an eml files.
.DESCRIPTION
Function will parse eml file and return a normalized object that can be used to extract infromation from the encoded file.
.PARAMETER EmlFileName
A string representing the eml file to parse.
.EXAMPLE
PS C:\> Convert-EmlFile -EmlFileName 'C:\Test\test.eml'
.OUTPUTS
System.Object
#>
[CmdletBinding()]
[OutputType([object])]
param
(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]
$EmlFileName
)
# Instantiate new ADODB Stream object
$adoStream = New-Object -ComObject 'ADODB.Stream'
# Open stream
$adoStream.Open()
# Load file
$adoStream.LoadFromFile($EmlFileName)
# Instantiate new CDO Message Object
$cdoMessageObject = New-Object -ComObject 'CDO.Message'
# Open object and pass stream
$cdoMessageObject.DataSource.OpenObject($adoStream, '_Stream')
return $cdoMessageObject
}