Solved

Export-Mailbox + Powershell Script

Posted on 2013-02-01
6
654 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

 
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
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…
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…

734 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