Modify an Exchange PowerShell Script

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
vhaperbaugubAsked:
Who is Participating?
 
Glen KnightConnect With a Mentor Commented:
Just before the -confirm:$false
0
 
Glen KnightCommented:
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
 
vhaperbaugubAuthor Commented:
Will the script above run against a list of users?
0
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

 
Glen KnightCommented:
As in a CSV list?
0
 
vhaperbaugubAuthor Commented:
CSV or txt list.
0
 
Glen KnightCommented:
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
 
vhaperbaugubAuthor Commented:
Ok, I'll test it out and let you know.....Thanks
0
 
vhaperbaugubAuthor Commented:
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
 
vhaperbaugubAuthor Commented:
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
 
Glen KnightCommented:
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
 
vhaperbaugubAuthor Commented:
I want it to read the DisplayName, how would I modify the script to read the DisplayName and then process it?
0
 
Glen KnightCommented:
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
 
vhaperbaugubAuthor Commented:
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
 
vhaperbaugubAuthor Commented:
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
 
Glen KnightCommented:
Add: -Confirm:$false before the last }
0
 
vhaperbaugubAuthor Commented:
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
 
vhaperbaugubAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.