Skip to content

Instantly share code, notes, and snippets.

@Add-STPE
Created December 8, 2019 07:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Add-STPE/e9d7993a6da6fd45a57e6dcbeb46da23 to your computer and use it in GitHub Desktop.
Save Add-STPE/e9d7993a6da6fd45a57e6dcbeb46da23 to your computer and use it in GitHub Desktop.
Clear-Host
$navne = "MAJE", "ASHO"
# Create an instance of the Outlook API.
Add-Type -AssemblyName "Microsoft.Office.Interop.Outlook"
$outlook = New-Object -ComObject Outlook.Application
$nameSpace = $outlook.GetNameSpace("MAPI")
$html = New-Object -ComObject "HTMlFile"
# Saves all the mails from folder Nye Til Oprettlse to $mails, select property htmlbody and subject
$mails = $nameSpace.Folders.Item('hotline').Folders.Item('Indbakke').Folders.Item('@HOVSA''er').Folders.Item('@01Nye til oprettelse').Items | Select-Object -Property subject, htmlbody
# Look over each $navn in $navne and match it against $mail subject.
foreach ($navn in $navne) {
foreach ($mail in $mails) {
if($mail | Where-Object {$_.subject -match "$Navn"}) {
#$mail.HTMLBody
# Write the data to HTML, then select all tags <table>, parse and throw it to ConvertFrom-StringData
$html.IHTMLDOCUMENT2_write($mail.HTMLBody)
$data = $html.all.tags("table") | % innertext
$data = $data -split '\r?\n' -match '^[^:]+:[^:]+$' -replace ':\s*', '=' -join "`n" | ConvertFrom-StringData
$navn
$data
$data.clear()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment