-
Notifications
You must be signed in to change notification settings - Fork 0
/
Export-AllMailboxes.ps1
45 lines (34 loc) · 1.17 KB
/
Export-AllMailboxes.ps1
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
function Export-Mailbox{
[cmdletbinding()]
Param(
[Parameter(Mandatory = $False,
Position = 0,
HelpMessage = "Specify the users whose mailboxes should be exported.")]
[String[]]$Users,
[Parameter(Mandatory = $True,
HelpMessage = "Specify the destination path for the PST file.")]
[String]$OutPath,
[Parameter(Mandatory = $False,
HelpMessage = "If using a CSV file to import users, specify the path to that file here.")]
[String]$InputPath
)
BEGIN{
if($InputPath -NE $Null){
$FileReader = New-Object System.IO.StreamWriter -Arg $InputPath
$FileHandle.AutoFlush = $True
while($FileReader.EndOfStream -EQ $False){
$Users += $FileReader.ReadLine()
}
}
}
PROCESS{
foreach($User in $Users){
New-MailboxExportRequest -Mailbox $User.SamAccountName -FilePath $OutPath + "\" + $User.Name + ".pst"
}
}
END{
$FileReader.Flush()
$FileReader.Dispose()
$FileReader.Close()
}
}