Where do I put my line in this code to output to file? I want it to build it as it is processing the emails but I can't discern where this is taking place.
Honestly, I can't figure out what the output line syntax should be either. Something like this (IDK):
$Email | select SentOn, SenderName, Subject, bodysubstring | Format-Table -Auto | out-file c:\results.txt
Here is the code in its entirety. I am trying to write my email basic information to a text file that I can examine when traveling. Your help is greatly appreciated.
#connect to outlook
$GetOutlook = New-Object -com "Outlook.Application";
$olName = $GetOutlook.GetNamespace("MAPI")
$olxEmailFolder = $olName.GetDefaultFolder(‘playdude@playboy.com’)
$olxEmailFolder.Name
$olxEmailItem = $olxemailFolder.items
#show unread emails in inbox
$olxEmailItem | select SentOn, SenderName, Subject, @{n='bodysubstring';e={$_.body.substring(0,100)}} | 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)
}
}