Created
February 1, 2013 17:08
-
-
Save ddhahn/4692630 to your computer and use it in GitHub Desktop.
Count PST files in a list of paths
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$pstcount =0 | |
$totalsize=0 | |
$totalsizegb=0 | |
$officepstcount=0 | |
$officepstaverage=0 | |
$officepsttotal=0 | |
$file = new-item -type file -path "c:\temp\pstsearch-stats.txt" -force | |
$detailfile = new-item -type file -path "c:\temp\pstsearch-details.txt" -force | |
##Get List of servers from the input file | |
$listofservers = get-content -path c:\temp\fileservers.txt | |
add-content -path $file -value "path,TotalPSTCount,TotalPSTSize,TotalOverallSize,TotalOverallCount" | |
add-content -path $detailfile -value "PathtoPST,PSTFileName,SizeofPST" | |
foreach ($serverpath in $listofservers){ | |
write-host "--------------------------" | |
write-host "Processing: " $serverpath | |
#map drive to the server and share to reduce the path length | |
#ndr -name X -psprovider FileSystem -root $serverpath -outvar $junk | |
## Find ALL pst files at the path | |
$pstfiles = dir $serverpath -filter *.pst -recurse | |
#For Each PST file, add the total sizes and update counters | |
foreach ($pstfile in $pstfiles){ | |
#add content for individual pst files found | |
add-content $detailfile -value "$pstfile.fullname,$pstfile.name,$pstfile.length" | |
$totalsize = $totalsize + $pstfile.length | |
$officepsttotal = $officepsttotal + $pstfile.length | |
$officepstcount = $officepstcount + 1 | |
$pstcount = $pstcount + 1 | |
} | |
#calculate office specific stats | |
$officepstaverage = $officepsttotal/$officepstcount | |
$averagepstsize = ($totalsize/$pstcount)/1024/1024/1024 | |
$totalsizegb = ((($totalsize/1024)/1024)/1024) | |
#output office specific stats | |
add-content $file -value "$serverpath,$officepstcount,$officepsttotal,$totalsize,$pstcount" | |
#output status | |
write-host "PST files found so far:" $pstcount | |
write-host "PST data so far:" $totalsizegb "GB" | |
write-host "Average PST size so far: " $averagepstsize "GB" | |
#rdr -name X -outvar $junk | |
$officepsttotal =0 | |
$officepstcount=0 | |
$officepstaverage=0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment