Export PST for multiple users from Particular Folder

Sharing this script that can be used in case of mergers/seprations where you need to export data from multiple users mailboxes.

It reads the input from CSV file — email & networkid(samaccount name), run against exchange 2010 & export the users data from particular folder (transfer) to the share you have set as well name the pst based on network ids.

After downloading the script zip from below link, Please update below values according to your requirement.

https://gallery.technet.microsoft.com/scriptcenter/Export-PST-for-multiple-663ccae7

$exportfolder = “transfer”

$location = “\\Server\e$\Merger\PST”

To run the script just open exchange Shell, cd to the script directory.

Execute as –> .\MergerExportPst.ps1 .\merger.csv

What script is doing is importing the data from csv , forming the name of pst in $path variable

    $pemail = $i.Previousemail 
    $pemail = $pemail.trim() 
    $networkid = $i.Networkid 
    $networkid = $networkid.trim() 
    $path = $location + "\" + $networkid + ".pst" 

Executing the  NewMailboxExportRequest to export the data from a particular folder.(catching any exceptions using Try/Catch)

New-MailboxExportRequest -Mailbox $pemail -IncludeFolders $exportfolder/* -filepath $path -ExcludeDumpster   

 

PowerShell
<#     
    .NOTES 
    =========================================================================== 
     Created on:       3/31/2017 9:04 AM 
     Created by:       sukhijv 
     Organization:      
     Filename:         MergerExportPst.ps1 
    =========================================================================== 
    .DESCRIPTION 
        This script will export the PST files for list of suers. 
        Folder with name transfer would be extracted 
#> 
######################Functions######################## 
Function Write-Log 
{ 
    [CmdletBinding()] 
    param 
    ( 
        [Parameter(Mandatory = $true)] 
        [array]$Name, 
        [Parameter(Mandatory = $true)] 
        [string]$Ext, 
        [Parameter(Mandatory = $true)] 
        [string]$folder 
    ) 
     
    $log = @() 
    $date1 = get-date -format d 
    $date1 = $date1.ToString().Replace("/""-") 
    $time = get-date -format t 
     
    $time = $time.ToString().Replace(":""-") 
    $time = $time.ToString().Replace(" """) 
     
    foreach ($n in $name) 
    { 
         
        $log += (Get-Location).Path + "\" + $folder + "\" + $n + "_" + $date1 + "_" + $time + "_.$Ext" 
    } 
    return $log 
} 
$log = Write-Log -Name "log1""log2" -Ext log -folder Logs 
Start-Transcript -Path $log[0] 
##########################Import CSv & START EXPORT################ 
$exportfolder = "transfer" 
$location = "\\Server\e$\Merger\PST" 
$data = Import-Csv $args 
foreach ($i in $data) 
{ 
    $pemail = $i.Previousemail 
    $pemail = $pemail.trim() 
    $networkid = $i.Networkid 
    $networkid = $networkid.trim() 
    $path = $location + "\" + $networkid + ".pst" 
    try 
    { 
        Write-Host "Processing...........$pemail................$networkid" -ForegroundColor Green 
        New-MailboxExportRequest -Mailbox $pemail -IncludeFolders $exportfolder/* -filepath $path -ExcludeDumpster     
    } 
    catch 
    { 
        Write-Host "Exception has occured processing $pemail....$networkid" -ForegroundColor Yellow 
        $_.Exception.Message 
    } 
} 
Stop-Transcript 
######################################################################

 

Thanks for reading

Sukhija Vikas

http://SysCloudPro.com

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s