Solved

Export-Mailbox + Powershell Script

Posted on 2013-02-01
6
663 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

615 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