Consolidate PST files
January 25, 2012 in Exchange 2010
Published: 2012-01-25
Updated: -
Version: 1.0
A time ago I was developing a PowerShell script for finding all PST files on a drive and copying them to a folder.
Type in a drive that should be searched and the UNC path to save them on
The script have been tested and verified on Exchange 2010 SP2
They are divided into two separate scripts.
Feel free to give feedback on it.
It can be downloaded here.
#############################################################################
# Search&Copy-PSTFiles.ps1
# Description
# This PowerShell script searches for *.pst files and copies them into the
# specified UNC location for the final step, the import of the pst contents
# into the associated mailboxes.
#
#
# Jonas Andersson, MCC 2011
# http://www.testlabs.se/blog
# Twitter @jonand82
#############################################################################
# Find PST Files
#Date
$date = Get-Date
$filename = "PST_Files_{0:yyyyMMdd-HHmm}.csv" -f (Get-Date)
$log = "log_{0:yyyyMMdd-HHmm}.txt" -f (Get-Date)
# End of variables
#Functions
#Searching for PST files
Function Search ($PST) {
[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
$drive = [Microsoft.VisualBasic.Interaction]::InputBox("Which drive do you want to search? (C:\)", "Drive (C:\)", "C:\")
[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
$unc = [Microsoft.VisualBasic.Interaction]::InputBox("Where do you want to save the PST files? UNC path for the Fileshare (\\server\share)", "UNC path", "Example: \\server\share")
WriteLog "Starting the search for PST files.."
$PSTFiles = Get-ChildItem -Path $drive -Recurse -Filter "*.pst"
if ($PSTFiles.count -eq $null){
WriteLog "No PST files were found.."
}
else{
$PSTFiles | Select-Object Name,Length,Directory | Out-File $log -append
$PSTFiles | Copy-Item -Destination $unc | Out-File $log -append
$PSTFiles | Select-Object Name,Length,Directory | Export-CSV -path $filename -Encoding Unicode -NoTypeInformation
WriteLog "PST files was found and copied successfully."
}
}
#Writes to log file
Function WriteLog ([string] $sLogMsg) {
$sLogLine=(get-date).Tostring("yyyy-MM-dd-HHmm")+","+$sLogMsg
$sLogLine| out-file $log -noclobber -append
}
#Script starts here
Search
WriteLog "Script completed!"
[System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”)
[Windows.Forms.MessageBox]::Show("Script completed!", "Information", [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Information)
End of script
The import script starts below
#############################################################################
# Import-PSTFiles.ps1
# Description
# This is the second part of the script that does the actual import of the
# pst contents into the associated mailboxes.
# Filenames is matched with the Alias value on the mailboxes.
#
#
# Jonas Andersson, MCC 2011
# http://www.testlabs.se/blog
# Twitter @jonand82
#############################################################################
# Find PST Files
# Load Exchange snapin
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction SilentlyContinue
#Date
$date = Get-Date
$filename = "PST_Files_{0:yyyyMMdd-HHmm}.csv" -f (Get-Date)
$log = "log_import_{0:yyyyMMdd-HHmm}.txt" -f (Get-Date)
# End of variables
#Functions
#Searching for PST files
Function Import ($PST) {
[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
$path = [Microsoft.VisualBasic.Interaction]::InputBox("Where are the PST files stored? UNC path for the Fileshare (\\server\share)", "UNC path", "Example: \\server\share")
[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
$archive = [Microsoft.VisualBasic.Interaction]::MsgBox("Should they be imported to the archive mailbox?",'YesNo,Question', "Import to archive?")
WriteLog "Starting the import of PST files.."
$PSTFiles = Get-ChildItem -Path $path -Filter "*.pst"
$PSTFiles | Select-Object Name,Length,Directory | Export-CSV -path $filename -Encoding Unicode -NoTypeInformation
if ($archive -eq "Yes"){
WriteLog "Starting the import to mailbox archive.."
Dir $path\*.pst | Out-File $log -append
$PSTFiles | %{ New-MailboxImportRequest -Name ImportToArchive -BatchName ImportToArchive -Mailbox $_.BaseName -FilePath $_.FullName -IsArchive } | Out-File $log -append
}
Else{
WriteLog "Starting the import to normal mailbox.."
Dir $path\*.pst | Out-File $log -append
$PSTFiles | %{ New-MailboxImportRequest -Name ImportToMailbox -BatchName ImportToMailbox -Mailbox $_.BaseName -FilePath $_.FullName } | Out-File $log -append
}
WriteLog "PST files was imported successfully."
}
#Writes to log file
Function WriteLog ([string] $sLogMsg) {
$sLogLine=(get-date).Tostring("yyyy-MM-dd-HHmm")+","+$sLogMsg
$sLogLine| out-file $log -noclobber -append
}
#Script starts here
Import
WriteLog "Script completed!"
[System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”)
[Windows.Forms.MessageBox]::Show("Script completed!", "Information", [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Information)
Feel free spread them just make sure to include a link to the blog as the source, use them at your own risk.





















[...] o link para mais informações:http://www.testlabs.se/blog/2012/01/25/consolidate-pst-files/ Gostar disso:GostoSeja o primeiro a gostar disso post. [...]
[...] Veja aqui: http://www.testlabs.se/blog/2012/01/25/consolidate-pst-files/ [...]
[...] http://www.testlabs.se/blog/2012/01/25/consolidate-pst-files/ [...]
What about Microsoft Exchange PST Capture tool?
It wasn’t released yet when I published the scripts..
And I didn’t know if it was going to be released or not
Use the scripts if you want and I would be happy to see feedback
Hi Jonas,
Kindly allow me to ask one query related to just release PST capture tool. Is it true that this tool only works on domain/AD networks? Kindly confirm to me so that I can resolved my doubt. Thanks in advance.
Hi and thanks for your comment
I haven’t tried the PST capture tool yet, but check the documentation around it
It can be found here: http://technet.microsoft.com/en-us/library/hh781036.aspx
[...] o link para mais informações: http://www.testlabs.se/blog/2012/01/25/consolidate-pst-files/ Gostar disso:GostoSeja o primeiro a gostar disso [...]