Monthly Archives: January 2012

Consolidate PST files

Consolidate PST files

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.

Download link

Can’t connect to Exchange using EMC / EMS

Can’t connect to Exchange using EMC / EMS

I was facing an issue after upgrading to Exchange 2010 SP2 in my lab environment.

When starting up the Management Shell and Console, it was telling me that it couldn’t connect to the Exchange server and that it couldn’t find an Exchange server in this site.

It was giving me the error message below
“The WinRM client cannot process the request. It cannot determine the content type of the HTTP response from the destination computer.”

After some research I found out that it could be because of the “WinRM IIS Extension” wasn’t installed.
So in my case I was adding it as a feature in Server Manager. (See the pic below)

During my research I also found out that if it was already installed, it should be uninstalled and run “winrm quickconfig”, restart.
And then install the feature again and run the command once again.

When it was installed, I tried to start the EMS again, with a great result J

Hope this post help those of you that faces the same issue that I did

Cheers!

Forum post around this: http://social.technet.microsoft.com/Forums/en-US/exchange2010/thread/5b82f131-b469-4661-9d6c-1c1c7939b73a