Solved

Modify an Exchange PowerShell Script

Posted on 2011-03-09
17
713 Views
Last Modified: 2012-05-11
Can the following Exchange PowerShell script be modified to run against a list of users and the output .pst file have the users name in it or something that associates to the user?

Export-Mailbox -Identity joe@va.gov –PSTFolderPath C:\Temp\joe.pst -DeleteContent
0
Comment
Question by:vhaperbaugub
  • 10
  • 7
17 Comments
 
LVL 74

Expert Comment

by:Glen Knight
ID: 35082037
You would use something like:

Get-Mailbox -Database “mailbox database” | Export-Mailbox -PSTFolderPath D:\PSTs -DeleteContent

This will automatically create a PST with the users Exchange Alias name.
0
 

Author Comment

by:vhaperbaugub
ID: 35082049
Will the script above run against a list of users?
0
 
LVL 74

Expert Comment

by:Glen Knight
ID: 35082051
As in a CSV list?
0
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

Author Comment

by:vhaperbaugub
ID: 35082086
CSV or txt list.
0
 
LVL 74

Expert Comment

by:Glen Knight
ID: 35082230
import-csv "d:\scripts\spamrecipients.csv" | ForEach-object -process {Export-Mailbox -PSTFolderPath D:\PSTs -DeleteContent}

I would suggest taking away the -deletecontent part until you know it's workign.
0
 

Author Comment

by:vhaperbaugub
ID: 35082445
Ok, I'll test it out and let you know.....Thanks
0
 

Author Comment

by:vhaperbaugub
ID: 35083463
When I run : import-csv "c:\mailboxsizes\test.csv" | ForEach-object -process {Export-Mailbox -PSTFolderPath C:\Temp}


Its asking for the identity, looks like its not importing the csv file.
0
 

Author Comment

by:vhaperbaugub
ID: 35084079
Looking again, its importing the CSV file, i'm getting this:

cmdlet Export-Mailbox at command pipeline position 1
Supply values for the following parameters:
Identity:
0
 
LVL 74

Expert Comment

by:Glen Knight
ID: 35084155
So sorry, of course it is, we haven't told it what to read from the CSV file.

See the example here which combined with the one I gave you above should sort you out: http://www.minasi.com/forum/topic.asp?TOPIC_ID=23732
0
 

Author Comment

by:vhaperbaugub
ID: 35084318
I want it to read the DisplayName, how would I modify the script to read the DisplayName and then process it?
0
 
LVL 74

Expert Comment

by:Glen Knight
ID: 35084403
Try:

foreach ($user in (Import-CSV "C:\export-mailbox.csv")) { Export-Mailbox "$($user" -PSTFolderPath "C:\Temp" }

(I'm mobile at the moment so if that doesn't work I will check it out when I get back to my desk)
0
 

Author Comment

by:vhaperbaugub
ID: 35084957
It doesn't seem to run, I believe the "$($user" portion seems to be the culprit. I tried some mods but nothing seems to work.
0
 

Author Comment

by:vhaperbaugub
ID: 35086228
I got it to work.....I used "$($user.displayname)"

Do you know what switch to use to make the script run without prompting me for "yes" or "no" for each user?
0
 
LVL 74

Expert Comment

by:Glen Knight
ID: 35086259
Add: -Confirm:$false before the last }
0
 

Author Comment

by:vhaperbaugub
ID: 35086427
That worked.....here is what it looks like:

foreach ($user in (Import-CSV "C:\mailboxsizes\test.csv")) { Export-Mailbox "$($user.displayname)" -PSTFolderPath "C:\Temp" -Confirm:$false  }

When I'm ready, where do I place -DeleteContent in the script?
0
 
LVL 74

Accepted Solution

by:
Glen Knight earned 500 total points
ID: 35086434
Just before the -confirm:$false
0
 

Author Comment

by:vhaperbaugub
ID: 35086478
Ok, I think that about does it for this.....Thanks for your help!!!!.....you saved me hours of time with the mods to this script.
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Marketers need statistics and metrics like everybody else needs oxygen. In this article we explain how to enable marketing campaign statistics for Microsoft Exchange mail.
This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
In this video we show how to create a Contact in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >> Contact ta…
The video tutorial explains the basics of the Exchange server Database Availability groups. The components of this video include: 1. Automatic Failover 2. Failover Clustering 3. Active Manager

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question