Solved

Powershell Scripting

Posted on 2013-01-31
3
282 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

"Migrate" an SMTP relay receive connector to a new server using info from an old server.
Easy CSR creation in Exchange 2007,2010 and 2013
The viewer will learn how to count occurrences of each item in an array.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

746 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

10 Experts available now in Live!

Get 1:1 Help Now