Powershell script to perform exchange admin tasks

Hi Experts,

I am kind of rush with the export of bulk mailboxes to a PST files and the EAC really sucks to perform bulk email searches and then export the results to multiple PST

Need you help to build a PowerShell script that basically will read from an input CSV file that contains exchange display name, database, and email address

So, for any member on the CSV file

Perform following tasks

' comment, the cmdlet below performs a new search against all sourcemailboxes specified there, but we should use display names for each user within the csv file

New-MailboxSearch -Name "Legal" -SourceMailboxes user1,user2 -TargetMailbox "LegalDiscovery" -StartDate "03/01/2013" -EndDate "07/02/2013" -SearchQuery 'Item1 OR item2'

' perform a search of the entire mailbox to a PST and no search criteria defined
New-MailboxExportRequest -Mailbox User1 -IncludeFolders "#Inbox#" -FilePath \\SERVER01\PSTFileShare\User1\User1.pst

'Once it finished the first search and export for the first user, will perform the remove-mailboxexportrequest to release resources. validate the pst has been created on the shared folder

Get-MailboxExportRequest | Remove-MailboxExportRequest

then repeat the entire process for each user in the CSV file

Can someone please help me with this request?
Jerry SeinfieldAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jerry SeinfieldAuthor Commented:
Any updates?

Please, do not neglect this question

Thanks in advance
Will SzymkowskiSenior Solution ArchitectCommented:
Give the below a try... I have not tested this so please test in a lab or with one account before doing a bulk import.

Make sure that your CSV has DisplayName and EmailAddress with NO spaces in the column headings.

$Import = import-csv "c:\filename.csv"
ForEach ($line in $Import) 

    {
        $line.DisplayName
        $line.database
        $line.emailaddress
        
            New-MailboxSearch -Name "Legal" -SourceMailboxes $line.DisplayName -TargetMailbox "LegalDiscovery" -StartDate "03/01/2013" -EndDate "07/02/2013" -SearchQuery 'Item1 OR item2'
            
            New-MailboxExportRequest -Mailbox $line.Emailaddress -IncludeFolders "#Inbox#" -FilePath "\\SERVER01\PSTFileShare\($line.DisplayName).pst"

            $CheckCompleted = Get-MailboxExportRequest -Status "Completed"

               if ($CheckCompleted -eq "Completed")

                    {

                    $CheckCompleted | Remmove-NewMailboxExportRequest
              } 


}

Open in new window


Will.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.