Created
December 8, 2019 07:40
-
-
Save Add-STPE/e9d7993a6da6fd45a57e6dcbeb46da23 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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