Solved

Export-Mailbox + Powershell Script

Posted on 2013-02-01
6
643 Views
Last Modified: 2013-02-04
Ladies and Gents,

I am looking to modify the following code:

$content = get-content "c:\test.txt"
start-transcript C:\exportmailbox.txt
foreach ($user in $content){
$Access = (Get-Mailbox $user | Get-MailboxPermission | where {$_AccessRights -eq "FullAccess"}).User
if($Access -notcontains "domain\username"){
add-mailboxpermission -Id $user -User “testadmin” -AccessRights FullAccess -Deny:$false}
export-mailbox $user -IncludeFolders "\Inbox","\Sent Items","\Deleted Items" -pstfolderpath c:\$user._Mailbox.pst
stop-transcript}

Open in new window


The specific section would be the

pstfolderpath c:\$user._Mailbox.pst

Open in new window


I would like to do the following:

lets assume the following:

The Users Name is "John Smith"
Then I would like the pstfolderpath to read pstfolderpath c:\jsmith.pst

Assume that the Active Directory account name for John Smith does not contain jsmith as the return.
0
Comment
Question by:itguy565
  • 3
  • 3
6 Comments
 
LVL 16

Accepted Solution

by:
Rajitha Chimmani earned 500 total points
ID: 38844212
You can try the code below to get JSmith as file name. What do you want the name to be if AD account name has Jsmith?

$content = get-content "c:\test.txt"
start-transcript C:\exportmailbox.txt
foreach ($user in $content){
$Access = (Get-Mailbox $user | Get-MailboxPermission | where {$_AccessRights -eq "FullAccess"}).User
if($Access -notcontains "domain\username"){
[string]$Filename =  $user.substring(0,1)+$user.split(" ")[1]
add-mailboxpermission -Id $user -User “testadmin” -AccessRights FullAccess -Deny:$false}
export-mailbox $user -IncludeFolders "\Inbox","\Sent Items","\Deleted Items" -pstfolderpath c:\$Filename.pst
stop-transcript}

Open in new window

0
 
LVL 11

Author Comment

by:itguy565
ID: 38844238
What do you want the name to be if AD account name has Jsmith?

if the AD already shows "jsmith" then leave the value jsmith.
0
 
LVL 16

Expert Comment

by:Rajitha Chimmani
ID: 38844277
I mean what you want the name of the file to be? Is it the AD account name or "First letter of first name and last name" as in JSmith?
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 11

Author Comment

by:itguy565
ID: 38844498
Yes,

The file  should be "jsmith.pst" even if the name in active directory says otherwise.

Thanks for you assistance thus far.
0
 
LVL 16

Expert Comment

by:Rajitha Chimmani
ID: 38844504
ok..then my script will do it..try that and let me know if your stuck.
0
 
LVL 11

Author Comment

by:itguy565
ID: 38850918
The script is perfect. Thanks, sorry it took me so long to get back to ya.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
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.
To show how to generate a certificate request 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 Servers >> Certificates…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

830 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