Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Export-Mailbox + Powershell Script

Posted on 2013-02-01
6
Medium Priority
?
680 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 2000 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
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.

 
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

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Question has a verified solution.

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

One-stop solution for Exchange Administrators to address all MS Exchange Server issues, which is known by the name of Stellar Exchange Toolkit.
Want to know how to use Exchange Server Eseutil command? Go through this article as it gives you the know-how.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

772 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