Util/Get-HawkMessageHeader.ps1
Function Get-HawkMessageHeader { param ( [Parameter(Mandatory = $true)] $Emlfile ) $ol = New-Object -ComObject Outlook.Application $msg = $ol.CreateItemFromTemplate("C:\temp\msg\RE_ Hawk Feedback - Install.msg") $header = $msg.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x007D001E") $headersWithLines = $header.split("`n") [string]$CombinedString = $null [array]$Output = $null foreach ($string in $headersWithLines) { if (!([string]::IsNullOrEmpty($string)) -and ([char]::IsWhiteSpace($string[0]))) { $string = $string.trimstart() $string = $string.trimend() $string = " " + $string [string]$CombinedString += $string # Write-host $CombinedString.Length } # If we are here we do a null check just in case but we know the first char is not a whitespace # So we have a new "object" that we need to process in elseif (!([string]::IsNullOrEmpty($string))) { # For the inital pass the string will be null or empty so we need to check for that if ([string]::IsNullOrEmpty($CombinedString)) { # Create our new string and continue processing $CombinedString = ($string.trimend("`r`n")) } else { # We should have everything now so create the object $Object = $null $Object = New-Object -TypeName PSObject # Get-CleanString -string $CombinedString # Split the string and add it to the object [array]$StringSplit = $CombinedString -split ":",2 $Object | Add-Member -MemberType NoteProperty -Name "Header" -Value $StringSplit[0] $Object | Add-Member -MemberType NoteProperty -Name "Value" -Value $StringSplit[1] # Add to the output array [array]$Output += $Object # write-host $output.Count # Create our new string and continue processing $CombinedString = $string.trimend() #Write-Host $CombinedString } } else { write-Error "boom" } } Return $Output } |