PoshCode Archive  Artifact [2385438807]

Artifact 2385438807ccc5da0768767540c31b3e2bfd269f6d5f4976ebc7b8c6b8b319e9:

  • File PSTMapper.ps1 — part of check-in [4f69f84324] at 2018-06-10 14:08:46 on branch trunk — This script will help a user to batch connect multiple pst files in Microsoft Outlook (personal email archives). (user: Jack Neff size: 1816)

# encoding: ascii
# api: powershell
# title: PSTMapper
# description: This script will help a user to batch connect multiple pst files in Microsoft Outlook (personal email archives).
# version: 0.1
# type: script
# author: Jack Neff
# license: CC0
# x-poshcode-id: 6134
# x-derived-from-id: 6135
# x-archived: 2017-04-17T14:32:28
# x-published: 2017-12-07T23:47:00
#
#
#This script will map multiple pst files automatically
#If you work helpdesk like me, it will save you years on your life (not kidding)

#This bit of code is optional, its just to pretty up the shell
$host.ui.RawUI.WindowTitle = "PST Mapper"
$host.UI.RawUI.BackgroundColor = 'DarkBlue'
$host.UI.RawUI.ForegroundColor = 'White'
Clear-Host

[Reflection.Assembly]::LoadWithPartialname("Microsoft.Office.Interop.Outlook") | Out-Null
$outlook = New-Object -ComObject Outlook.Application

[string]$rootFolder = Read-Host "`nPath where your PST files are located"

#Do a recursive search of all subfolders for pst files
#Makes it possible for a user to just type "C:" if they aren't sure where their pst's are stored
$pstFiles = Get-ChildItem -Path $rootFolder -Filter *.pst -Recurse

if ($pstFiles) {
    $pstFiles | sort LastWriteTime -Descending | select LastWriteTime, Fullname | ft -auto 
} else {
    Write-Host "No pst files found" -ForegroundColor Red
    Start-Sleep -Seconds 5
    Break
}

#Users generally will keep older archived pst files they don't need to connect so this allows
#them to select files by date
[datetime]$cutoff = Read-Host "Only map files newer than (date)"

Write-Host "`nMapping pst files now.  This window will automatically close when the process is complete"

$pstFiles | where { $_.LastWriteTime -ge $cutoff } | ForEach-Object { $outlook.Session.AddStore($_.FullName) }