Solved

Powershell Scripting

Posted on 2013-01-31
3
288 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
[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
  • 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
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…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

726 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