Solved

Powershell Scripting

Posted on 2013-01-31
3
284 Views
Last Modified: 2013-01-31
Ladies and Gents,

I am looking to modify this script to add logic to it.

$content = get-content "c:\test.txt"

foreach ($user in $content)
{export-mailbox $user -IncludeFolders "\Inbox","\Sent Items","\Deleted Items" -pstfolderpath c:\$user._Mailbox.pst}

Open in new window


(The logic I would like to add would be a check)

To make sure that I have full mailbox rights prior to attempting the export mailbox command.

add-mailboxpermission -Id “$user” -User “testadmin” -AccessRights FullAccess -Deny:$false

Open in new window


If FullAccess is found to be false then run the above command and make it true.

I need the logic statement listed above to be a  challenge statement at the beginning of the script

Note the $user var at the top. This data will be pulled from an external source called test.txt
0
Comment
Question by:itguy565
  • 2
3 Comments
 
LVL 11

Author Comment

by:itguy565
ID: 38842110
I would also like to add code that will export the entire output to a log file in the same file location. (c:\exportMailbox.log}
0
 
LVL 16

Accepted Solution

by:
Rajitha Chimmani earned 500 total points
ID: 38842495
You can use something like the below

$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

0
 
LVL 11

Author Closing Comment

by:itguy565
ID: 38842532
Thanks for the fast reply, that was exactly what I needed.
0

Featured Post

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.

Question has a verified solution.

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

Utilizing an array to gracefully append to a list of EmailAddresses
Granting full access permission allows users to access mailboxes present in their database. By giving full access permission one can open and read the content of any mailbox but cannot send emails from that mailbox.
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 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…

920 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

13 Experts available now in Live!

Get 1:1 Help Now