【问题标题】:How do I reference Folder and Subfolder如何引用文件夹和子文件夹
【发布时间】:2013-06-30 13:02:31
【问题描述】:

如何引用电子邮件文件夹和子文件夹?在我的代码的第 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)
   }
}

【问题讨论】:

  • 您看到了什么错误?这对我来说很好。
  • 我没有收到错误,我的专栏中什么也没有。
  • 移动你的 | Out-File "C:\results.txt" - 附加到写入行的末尾。一切都会好起来。

标签: powershell automation mailitem


【解决方案1】:

给你椰子干:

#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 SentOn, SenderName, Subject, Body | Format-Table -auto | Out-File "C:\A_results.txt"

#go through each subfolder and get name
$SubFolders = $olxEmailFolder.Folders 

ForEach($Folder in $SubFolders)
{
   $Folder.Name | select $Folder.Name | Format-Table -auto | Out-File "C:\A_results.txt" -Append 
   $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)
   $Email | select SentOn, SenderName, Subject, Body | Format-Table -Auto | Out-File "C:\A_results.txt" -Append
   }
}
#connect to tasks
$olxTasksFolder = $olName.GetDefaultFolder(‘olFolderTasks’)
$olxTaskItems = $olxTasksFolder.items
$TaskCount = 1
#create task array
$TaskList = @()
ForEach($TaskItem in $olxTaskItems)
{
#create status bar for tasks
   Do
   {
     Write-Progress -Activity "Checking" -status "Tasks" -PercentComplete ($Taskcount/$olxTasksFolder.Items.count*100) | select $Taskcount, $olxTasksFolder.Items | Out-File "C:\D_results.txt"
     $TaskCount++
   }
#add each incomplete tash to array
   While($TaskCount -le $olxTaskFolder.Items.Count)
   If($TaskItem.Complete -eq $False)
   {
   $TaskList+=New-Object -TypeName PSObject -Property @{
   Subject=$TaskItem.Subject
   DateCreated=$TaskItem.CreationTime
   Percent=$TaskItem.PercentComplete
   Due=$TaskItem.DueDate
   }}
}
#show task array to screen
#$TaskList | Sort DueDate -descending | Format-Table -Auto 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-21
    • 1970-01-01
    • 2020-07-18
    • 1970-01-01
    相关资源
    最近更新 更多