PoshCode Archive  Artifact [74b34fb01b]

Artifact 74b34fb01be636212ffcb818a5783a5c2594e7b32a75cb94d86824e6a516eab3:

  • File Powershell-Only-Outlook.ps1 — part of check-in [e5c0d022b7] at 2018-06-10 14:10:36 on branch trunk — My first contribution. I am crazily thinking of doing a “Powershell Only” day. The first task is to figure out how to manipulate Outlook through PowerShell. The submitted script hits my Outlook inbox and goes through the inbox and each subfolder and retrieves the unread emails from it. It then goes through my task list and gets all the incomplete tasks. This was my first time using a status bar and definitely the first for making anything outside the scripting games public. I’d hate to get finished with the Outlook “module” and find out I could have saved myself a lot of time, so I through the script as it is now on the mercy of the court. Proceed with your red pens… (user: chris seiter size: 2754)

# encoding: utf-8
# api: powershell
# title: Powershell Only Outlook
# description: My first contribution.  I am crazily thinking of doing a “Powershell Only” day.  The first task is to figure out how to manipulate Outlook through PowerShell.  The submitted script hits my Outlook inbox and goes through the inbox and each subfolder and retrieves the unread emails from it.  It then goes through my task list and gets all the incomplete tasks.  This was my first time using a status bar and definitely the first for making anything outside the scripting games public.  I’d hate to get finished with the Outlook “module” and find out I could have saved myself a lot of time, so I through the script as it is now on the mercy of the court.  Proceed with your red pens…
# version: 0.1
# author: chris seiter
# license: CC0
# x-poshcode-id: 6214
# x-derived-from-id: 6215
# x-archived: 2016-05-17T17:21:16
# x-published: 2016-02-12T08:27:00
#
#
#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 | ?{$_.Unread -eq $True} | 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 | ?{$_.Unread -eq $True} | 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