Solved

Powershell Scripting

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

Synchronize a new Active Directory domain with an existing Office 365 tenant
A brief introduction to what I consider to be the best editor for PowerShell.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

825 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