-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-OutlookFolderInfo.ps1
More file actions
58 lines (51 loc) · 1.8 KB
/
Get-OutlookFolderInfo.ps1
File metadata and controls
58 lines (51 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
function Get-MailboxFolder {
param($folder)
[pscustomobject]@{
Path = $folder.FullFolderPath
Count = $folder.items.count
}
foreach ($f in $folder.folders) {
Get-MailboxFolder $f
}
}
function Get-OutlookFolderCount {
[cmdletbinding()]
param(
$root = "Spam Reporting (OSUWMC)",
$folders = $null
)
process {
$obj = @()
try {
$outlook = New-Object -ComObject Outlook.Application -ErrorAction Stop
$RootFolder = $outlook.Session.Folders.Item($root).Folders
}
catch [System.Runtime.InteropServices.COMException] {
Write-Warning "Outlook not installed or root folder does not exist"
break
}
# iterates over all folders and ultimatly gets the full path and count
foreach ($folder in $RootFolder) {
foreach ($mailfolder in $folder.Folders) {
$obj+=Get-MailboxFolder $mailfolder
}
}
if ($folders) {
$dt = Get-Date (Get-Date).AddDays(-1) -Format "MM-dd-yyyy"
foreach ($folder in $folders) {
$path = "$folder$dt"
$obj.where({$_.path -eq $path})
}
} else {
$obj
}
}
}
# define our list of folder that we want numbers from
$folders = '\\Spam Reporting (OSUWMC)\Inbox\Non Report SPAM\',
'\\Spam Reporting (OSUWMC)\Inbox\Report Phish Reports\By Date\',
'\\Spam Reporting (OSUWMC)\Inbox\Report Phish Reports\eusafe\',
'\\Spam Reporting (OSUWMC)\Inbox\Report Phish Reports\safe\'
#Get-OutlookFolderCount -root "Spam Reporting (OSUWMC)" | Out-GridView
#Get-OutlookFolderCount -root "Spam Reporting (OSUWMC))" -folders $folders | Out-GridView
#Get-OutlookFolderCount -root "Wes.Stahler@osumc.edu" | Out-GridView