Jump to content

Recommended Posts

Posted (edited)

Hi

I have a script that I am working on to export a users mailbox to PST if the mailbox PST does not already exist based on the users OU. I am running this on our Exchange 2013 server and I want to eventually run this as a sceduled task.

I have created a profile.ps1 and placed this in "C:\Windows\System32\Windows Powershell\V1.0", it contains:

 

. "C:\Program Files\Microsoft\Exchange Server\V15\Bin\RemoteExchange.ps1"

Connect-ExchangeServer -Auto

 

I can right click my "ArchiveMailbox.ps1" and run with powershell and it will export every users mailbox that is in the oU, what I want is to add a check to only export the mailbox if the mailbox has not already been exported. If I try to run this from task scheduler it does nothing.

 

Start a Program

"powershell.exe"

 

Argument

"C:\Scripts\ArchiveMailbox.ps1"

 

Here is my script

 

# Variables

$Users = Get-Mailbox -OrganizationalUnit $OU

$OU = "{doman}/{path}"

$filepath = "\\filesrv1\archive$\PST"

$TestPath = $FilePath+($_.Alias)+".pst"

$FileExists = Test-Path $TestPath

 

# Move leavers home folder to Archive share

$users | % {

if ($FileExists -eq $false)

{

Write-Host "File does not exist"

}

Else

{

New-MailboxExportRequest -Mailbox $_.Alias -FilePath ($FilePath+($_.Alias)+".pst") -ExcludeFolders "#SentItems#", "#Drafts#", "#DeletedItems#", "#JunkEmail#" -ExcludeDumpster

}

}

Edited by ZeroHour

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...