1

How do I get the display to kick out to a text file?

#show task array to screen
$TaskList | Sort DueDate -descending | Format-Table -Auto

Here is the code in its entirety:

#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

#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)
   $Email | select SentOn, SenderName, Subject, Body | Format-Table -Auto
   }
}
#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)
     $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
Jonathan Morningstar
  • 421
  • 3
  • 11
  • 25

2 Answers2

1

To add to dugas' comment, the command would be:

$TaskList | Sort DueDate -descending | Format-Table -Auto | out-file c:\results.txt

You could make it more useful by exporting to CSV format.

$TaskList | Sort DueDate -descending | Format-Table -Auto | export-csv c:\results.csv -notypeinformation
Bagheera
  • 1,358
  • 4
  • 22
  • 35
0

You can use the Out-File cmdlet.

Chris Pratt
  • 232,153
  • 36
  • 385
  • 444
dugas
  • 12,025
  • 3
  • 45
  • 51