Exchange 2010

Search for PST files on clients

Wrote a basic PowerShell script that searches all computers listed in the clients.txt file.

Saving the pst files into the destination path.

For each computer, a folder is created with the corresponding computer name so that the PST files is collected per client.

Before the PST Capture Tool was released I wrote a post about “How to consolidate PST” files.
This script is just a little adjustment of that one.

Also have a look at the PST Capture Tool, it can be found here.

Anyway, feel free to use the script below and comment on it

#############################################################################
# Search.ps1
# Description:
# This PowerShell script searches for *.pst files on the clients listed in
# the clients.txt file (one hostname per row). Then saves them on the path specified
# in $SavePath, one folder per computer is created in the destionationpath.
#
# Jonas Andersson, MCC 2011
# http://www.testlabs.se/blog
# Twitter @jonand82
#############################################################################

$data = Get-Content .\clients.txt
$Date = Get-Date -Format yyyyMMddHHmm
$Log = "log_{0:yyyyMMdd-HHmm}.txt" -f (Get-Date)

#Writes to log file
Function WriteLog ([string] $sLogMsg) {
$sLogLine=(get-date).Tostring("yyyy-MM-dd-HHmm")+","+$sLogMsg
$sLogLine| out-file $log -noclobber -append
}

foreach ($row in $data)
{
WriteLog "Starting the search for PST files on $row."
$FindPath = "\\$row\c$"
$SavePath = "\\destionaionpath\pstshare"

$PSTFiles = Get-ChildItem -Path $FindPath -Recurse -Filter "*.pst"

if ($PSTFiles.count -eq $null) {
WriteLog "No PST files were found on computer $row."
}
else {
$PSTFiles | New-Item -path $SavePath -name $row -itemtype directory -force
$PSTFiles | Copy-Item -Destination "$SavePath\$row"
WriteLog "PST files was found and copied successfully on computer $row."
}
}

WriteLog "Script completed!"

Download link

Tagged , , , , ,