如何引用电子邮件文件夹和子文件夹?在我的代码的第 8 行中,我在 olxEmailFolder 和所有其他获取文件夹的尝试中都失败了。有什么想法吗?
#connect to outlook
$GetOutlook = New-Object -com "Outlook.Application";
$olName = $GetOutlook.GetNamespace("MAPI")
$olxEmailFolder = $olName.GetDefaultFolder('olFolderInbox')
$olxEmailFolder.Name
$olxEmailItem = $olxemailFolder.items
#show unread emails in inbox
$olxEmailItem | select olxEmailFolder, ReceivedByName, SentOnBehalfOfName, SentOn, Subject, Body | Format-Table -auto | Out-File "C:\results.txt"
#go through each subfolder and get name
$SubFolders = $olxEmailFolder.Folders
ForEach($Folder in $SubFolders)
{
$Folder.Name
$SubfolderItem = $Folder.Items
$EmailCount = 1
#create status bar for each subfolder
ForEach($Email in $SubfolderItem)
{
Do
{
Write-Progress -Activity "Checking folder" -status $Folder.Name -PercentComplete ($EmailCount/$Folder.Items.Count*100)
$EmailCount++
}
#show unread emails from subfolders
While($EmailCount -le $Folders.Item.Count)
}
}