Solved

Export-Mailbox + Powershell Script

Posted on 2013-02-01
6
631 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Resolve DNS query failed errors for Exchange
Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
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
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)

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now