当创建它的 .msg 文件具有使用 PowerShell 的正文文本时,-comobject 的主体为 Null

问题描述 投票:0回答:0

更新:见下文 因此,我试图从一个充满 .msg 文件的文件夹中收集正文。我现在正在使用 PowerShell,因为我认为这是一种绕过某些工作场所权限的方法。

原谅我,因为我还在研究问题格式。

这就是我正在做的

$output = ""
## get all the .msg files in the folder
#Get-ChildItem "C:\Users\myfolder" -Filter  *.msg |
##single test example for testing
Get-ChildItem 'C:\Users\myfolder\Testemail.msg' |

ForEach-Object{
    $outlook = New-Object -comobject outlook.application
    $msg = $outlook.CreateItemFromTemplate($_.FullName)

    ##what have i even created
    write-host 'what is $msg anyway'
    $msg
    ##some trouble shooting things i saw in another thread, may be commented out
    #$msg | Select senderemailaddress,to,subject,Senton,body|ft -AutoSize

    $strCreateTime = $msg.ReceivedTime.ToString('yyyy-MM-dd hh:mm')
    $subject = $msg.Subject.ToString()
    write-host 'Body'
    $body = $msg.Body
    write-host $Body
    write-host 'After body'
    

   

    ## add the email stuff e.g. subject, bodys to a uber string tab delimited
    $output = $output + $strCreateTime+"`t"+$subject+"`t`n`r"
    Write-Host $output


    }

当前输出为


what is $msg anyway

Application                       : Microsoft.Office.Interop.Outlook.ApplicationClass
Class                             : 43
Session                           : System.\__ComObject
Parent                            : System.\__ComObject
Actions                           : System.\__ComObject
Attachments                       : System.\__ComObject
BillingInformation                :
Body                              :
Categories                        :
Companies                         :
ConversationIndex                 :
ConversationTopic                 : Some test email
CreationTime                      : 1/01/4501 12:00:00 AM
EntryID                           :
FormDescription                   : System.\__ComObject
GetInspector                      : System.\__ComObject
Importance                        : 1
LastModificationTime              : 1/01/4501 12:00:00 AM
MAPIOBJECT                        : System.\__ComObject
MessageClass                      : IPM.Note
Mileage                           :
NoAging                           : False
OutlookInternalVersion            : 0
OutlookVersion                    :
Saved                             : True
Sensitivity                       : 0
Size                              : 0
Subject                           : Some test email
UnRead                            : True
UserProperties                    : System.\__ComObject
AlternateRecipientAllowed         : True
AutoForwarded                     : False
BCC                               :
CC                                :
DeferredDeliveryTime              : 1/01/4501 12:00:00 AM
DeleteAfterSubmit                 : False
ExpiryTime                        : 1/01/4501 12:00:00 AM
FlagDueBy                         : 1/01/4501 12:00:00 AM
FlagRequest                       :
FlagStatus                        : 0
HTMLBody                          :
OriginatorDeliveryReportRequested : False
ReadReceiptRequested              : False
ReceivedByEntryID                 :
ReceivedByName                    :
ReceivedOnBehalfOfEntryID         :   Ƛ졀䋀ᨐ릴⼫苡   伯䔽䍘䅈䝎䱅䉁⽓問䔽䍘䅈䝎⁅䑁䥍䥎呓䅒䥔䕖䜠佒偕⠠奆䥄佂䙈㌲偓䱄⥔䌯㵎䕒䥃䥐久協䌯㵎㔷㙄㐹㉄㄰㐸䔴䑂䄸㌴䅅ㅃ䐶䌳㈷㉅䌭乏䥄䥔乏位
ReceivedOnBehalfOfName            :
ReceivedTime                      : 17/07/2022 10:00:45 AM
RecipientReassignmentProhibited   : False
Recipients                        :
ReminderOverrideDefault           : False
ReminderPlaySound                 : False
ReminderSet                       : False
ReminderSoundFile                 :
ReminderTime                      : 1/01/4501 12:00:00 AM
RemoteStatus                      : 0
ReplyRecipientNames               :
ReplyRecipients                   :
SaveSentMessageFolder             : System.\__ComObject
SenderName                        :
Sent                              : False
SentOn                            : 17/07/2022 10:00:43 AM
SentOnBehalfOfName                :
Submitted                         : False
To                                :
VotingOptions                     :
VotingResponse                    :
Links                             :
ItemProperties                    : System.\__ComObject
BodyFormat                        : 2
DownloadState                     : 1
InternetCodepage                  : 28591
MarkForDownload                   : 0
IsConflict                        : False
IsIPFax                           : False
FlagIcon                          : 0
HasCoverSheet                     : False
AutoResolvedWinner                : False
Conflicts                         : System.\__ComObject
SenderEmailAddress                :
SenderEmailType                   : EX
EnableSharedAttachments           : True
Permission                        : 0
PermissionService                 : 0
PropertyAccessor                  :
SendUsingAccount                  :
TaskSubject                       : Some test email
TaskDueDate                       : 1/01/4501 12:00:00 AM
TaskStartDate                     : 1/01/4501 12:00:00 AM
TaskCompletedDate                 : 1/01/4501 12:00:00 AM
ToDoTaskOrdinal                   : 1/01/4501 12:00:00 AM
IsMarkedAsTask                    : False
ConversationID                    :
Sender                            : System.\__ComObject
PermissionTemplateGuid            :
RTFBody                           :
RetentionPolicyName               :
RetentionExpirationDate           : 1/01/4501 12:00:00 AM

Body

After body
2022-07-17 10:00    Some test email

注意

Body                              :

我希望这里有内容(字符串) 由于某种原因,正文没有内容,即使我知道电子邮件有内容。谁能建议

更新: 现在看起来是这样

$output = ""
## get all the .msg files in the folder
#Get-ChildItem "C:\Users\myfolder" -Filter  *.msg |
##single test example for testing
$outlook = New-Object -comobject outlook.application
Get-ChildItem 'C:\Users\myfolder\Testemail.msg' |

ForEach-Object{
    
    $msg = $outlook.CreateItemFromTemplate($_.FullName)

    ##what have i even created
    write-host 'what is $msg anyway'
    $msg
    ##some trouble shooting things i saw in another thread, may be commented out
    #$msg | Select senderemailaddress,to,subject,Senton,body|ft -AutoSize

    $strCreateTime = $msg.ReceivedTime.ToString('yyyy-MM-dd hh:mm')
    $subject = $msg.Subject.ToString()
    write-host 'Body'
    $body = $msg.Body
    write-host $Body
    write-host 'After body'
    

   

    ## add the email stuff e.g. subject, bodys to a uber string tab delimited
    $output = $output + $strCreateTime+"`t"+$subject+"`t`n`r"
    Write-Host $output


    }
    
 $outlook.Quit()
 $null = [System.Runtime.Interopservices.Marshal]::ReleaseComObject($outlook)

似乎仍然有效,但 Body 仍然是空的。如果有人可以提供帮助,我将不胜感激,即使是添加可以吸引有用用户的标签

powershell null text-mining
© www.soinside.com 2019 - 2024. All rights reserved.