Solved

Modify an Exchange PowerShell Script

Posted on 2011-03-09
17
712 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Scam emails are a huge burden for many businesses. Spotting one is not always easy. Follow our tips to identify if an email you receive is a scam.
This article explains how to install and use the NTBackup utility that comes with Windows Server.
In this video we show how to create a Resource Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: Navigate to the Recipients >> Resources tab.: "Recipients" is our default selection …
This video discusses moving either the default database or any database to a new volume.

809 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