Skip to content

Instantly share code, notes, and snippets.

@ringe
Last active December 15, 2015 07:59
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ringe/5227717 to your computer and use it in GitHub Desktop.
Save ringe/5227717 to your computer and use it in GitHub Desktop.
Say you want to export all your Exchange mailboxes to PST files, but would like to know which Active Directory "Windows" user names the mailboxes belongs to. Turns out it's not straightforward, unless there's something I don't get. First: Export a list of all AD users by their name, including their username - the one used in "DOMAIN\username", y…
# Then this in Exchange Management Shell
$Location = "\\server\pstexport"
New-Item -path $Location -name "migrate.txt" -type File -force
Add-Content "$Location\migrate.txt" "datasourceuser,destinationuser"
# Create a hash table of Exchange mailboxes
$mailboxes = @{}
Get-Mailbox | Select-Object name, alias |
ForEach-Object { $mailboxes.Add($_.name, $_.alias) }
$reader = [System.IO.File]::OpenText("c:\allusers.txt")
try { for(;;) {
$line = $reader.ReadLine()
if ($line -eq $null) { break }
# process the line
$name, $SamAccountName = $line.Split(",")
$ss = $name, $SamAccountName, $alias
$alias = $mailboxes.Get_Item("$name")
$ismbx = $mailboxes.ContainsKey($name)
$notspecial = $alias -notmatch [regex]::escape("{")
if (($ismbx) -and ($notspecial)) {
New-MailboxExportRequest -Mailbox $alias -FilePath "$Location\$alias.pst"
Add-Content "$Location\migrate.txt" "$alias.pst,$SamAccountName"
}
} }
finally {
$reader.Close()
}
# Run this in the Active Directory Module for Powershell
Get-ADUser -Filter * -Properties Name |
select-object name,SamAccountName |
convertto-csv -NoTypeInformation |
% { $_ -replace '"', ""} |
out-file c:\allusers.txt -fo -en unicode
Maybe you find use for this with Zarafa:
http://doc.zarafa.com/trunk/Migration_Manual/en-US/html-single/
Download the tool here:
http://download.zarafa.com/community/final/
@adom503
Copy link

adom503 commented Sep 24, 2013

Great project to export mailboxes by identifying Active directory user name. However exchange server gets corrupted or peoples want an automated way to export exchange mailboxes into pst file then help of an excellent exchange edb converter ( http://www.pcvita.com/export-exchange-mailbox.html ) is much appreciated. As I know, this is a way only to export mailboxes from offline or dismounted or corrupted edb file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment