在Powershell中,如何从Outlook的自定义文件夹(与收件箱相同级别)打印出数据?

时间:2015-02-27 16:16:36

标签: powershell

我有以下Powershell脚本:

$outlook = new-object -com Outlook.Application
$sentMail = $outlook.Session.GetDefaultFolder(6) # == olFolderSentMail
$sentMail.folders.item("FDA UFMS User Provision").Items |  %{ $RESULT=[Regex]::Match($_.TaskSubject ,"Request\s\d{6}"); if($RESULT.Success){$RESULT.Value}} | %{$Result=[regex]::Match($_,"\d{6}"); if($RESULT.Success){$RESULT.Value}} |
Out-File C:\Temp\Powershell_6_digit_Codes.txt -Append

但是,它不会从FDA UFMS User Provision文件夹中获取数据,因为它与收件箱位于同一级别(不在收件箱中)。

如何更改$sentMail.folders.item("FDA UFMS User Provision").Items的脚本以便获取此数据?

到目前为止我试过

$sentMail.item("FDA UFMS User Provision").Items

但是没有产生正确的结果。

enter image description here

谢谢!

1 个答案:

答案 0 :(得分:0)

这有效:

$outlook = new-object -com Outlook.Application

$sentMail = $outlook.Session.GetDefaultFolder(6) # == olFolderSentMail

$bigFolder = $sentMail.Parent


$ufms = "FDA UFMS User Provision"


$newufms = $bigFolder.folders.item($ufms)


$newufms.Items | %{ $RESULT=[Regex]::Match($_.TaskSubject, "Request\s\d{6}"); if ($RESULT.Success)

{$RESULT.Value}} | %{$Result=[Regex]::Match($_, "\d{6}"); if($RESULT.Success){$RESULT.Value}} | Out-File C:\Temp

\Powershell_6_digit_Codes.txt -Append