Move mailboxes via Powershell and Log results

Hi all,

I created a script to move mailboxes and log the results. The script reads 
the alias from a text file and moves the mailbox. When completed it logs the 
result to a CSV file.

I would like to modify the script to move 5 mailboxes at a time and log the 
results. I cannot seem to get it to work.

Below is the working script which allows one to move at a time. How can I 
modify it to move 5 at a time AND to log the results to the CSV file.

##############################################
$TargetDatabase = “SERVER01\SG03\MBX03”

$SourceFile = “x:\MAILMOVES.TXT”
$UserList = Get-Content $SourceFile

ForEach ($user in $userlist)		
{
$Date = Get-Date 
Move-Mailbox $user  -TargetDatabase $TargetDatabase -baditemlimit 50  
-PreserveMailboxSizeLimit:$False -Confirm:$False -ErrorAction 
SilentlyContinue | ForEach {$Alias = $_.Alias; $SourceDatabase = 
$_.SourceDatabase; $TargetDatabase = $_.TargetDatabase; $MailboxSize = 
$_.MailboxSize; $StatusMessage = $_.StatusMessage; $StatusCode = 
$_.StatusCode; 
   	
write-output "$Alias, $SourceDatabase, $TargetDatabase, $MailboxSize, 
$StatusMessage, $StatusCode, $Date" | Out-File "X:\Mailbox Moves Master.csv" 
-append	
}
}
0
Utf
2/16/2010 1:00:01 PM
windows.powershell 690 articles. 0 followers. Follow

6 Replies
1445 Views

Similar Articles

[PageSpeed] 27

Here's a hint/tip:

for($i=1;$i -lt (get-content my_file.txt).count;$i+=5){(get-content 
my_file.txt)[$i..($i+4)]}

You need to breakup your user list in chunks.

Let us know if you're still stuck...

Marco

"Don Pedro" <DonPedro@discussions.microsoft.com> wrote in message 
news:EE417062-DF05-4C2E-8320-80DFD6970C34@microsoft.com...
> Hi all,
>
> I created a script to move mailboxes and log the results. The script reads
> the alias from a text file and moves the mailbox. When completed it logs 
> the
> result to a CSV file.
>
> I would like to modify the script to move 5 mailboxes at a time and log 
> the
> results. I cannot seem to get it to work.
>
> Below is the working script which allows one to move at a time. How can I
> modify it to move 5 at a time AND to log the results to the CSV file.
>
> ##############################################
> $TargetDatabase = “SERVER01\SG03\MBX03”
>
> $SourceFile = “x:\MAILMOVES.TXT”
> $UserList = Get-Content $SourceFile
>
> ForEach ($user in $userlist)
> {
> $Date = Get-Date
> Move-Mailbox $user  -TargetDatabase $TargetDatabase -baditemlimit 50
> -PreserveMailboxSizeLimit:$False -Confirm:$False -ErrorAction
> SilentlyContinue | ForEach {$Alias = $_.Alias; $SourceDatabase =
> $_.SourceDatabase; $TargetDatabase = $_.TargetDatabase; $MailboxSize =
> $_.MailboxSize; $StatusMessage = $_.StatusMessage; $StatusCode =
> $_.StatusCode;
>
> write-output "$Alias, $SourceDatabase, $TargetDatabase, $MailboxSize,
> $StatusMessage, $StatusCode, $Date" | Out-File "X:\Mailbox Moves 
> Master.csv"
> -append
> }
> } 

0
Marco
2/16/2010 7:57:52 PM
Hi Marco,

Stuck? My head nearly exploded!

I just had flashbacks to my maths class and equations. Shiver...

Yes, I think I need more than a hint here.

Peter

"Marco Shaw [MVP]" wrote:

> Here's a hint/tip:
> 
> for($i=1;$i -lt (get-content my_file.txt).count;$i+=5){(get-content 
> my_file.txt)[$i..($i+4)]}
> 
> You need to breakup your user list in chunks.
> 
> Let us know if you're still stuck...
> 
> Marco
> 
> "Don Pedro" <DonPedro@discussions.microsoft.com> wrote in message 
> news:EE417062-DF05-4C2E-8320-80DFD6970C34@microsoft.com...
> > Hi all,
> >
> > I created a script to move mailboxes and log the results. The script reads
> > the alias from a text file and moves the mailbox. When completed it logs 
> > the
> > result to a CSV file.
> >
> > I would like to modify the script to move 5 mailboxes at a time and log 
> > the
> > results. I cannot seem to get it to work.
> >
> > Below is the working script which allows one to move at a time. How can I
> > modify it to move 5 at a time AND to log the results to the CSV file.
> >
> > ##############################################
> > $TargetDatabase = “SERVER01\SG03\MBX03”
> >
> > $SourceFile = “x:\MAILMOVES.TXT”
> > $UserList = Get-Content $SourceFile
> >
> > ForEach ($user in $userlist)
> > {
> > $Date = Get-Date
> > Move-Mailbox $user  -TargetDatabase $TargetDatabase -baditemlimit 50
> > -PreserveMailboxSizeLimit:$False -Confirm:$False -ErrorAction
> > SilentlyContinue | ForEach {$Alias = $_.Alias; $SourceDatabase =
> > $_.SourceDatabase; $TargetDatabase = $_.TargetDatabase; $MailboxSize =
> > $_.MailboxSize; $StatusMessage = $_.StatusMessage; $StatusCode =
> > $_.StatusCode;
> >
> > write-output "$Alias, $SourceDatabase, $TargetDatabase, $MailboxSize,
> > $StatusMessage, $StatusCode, $Date" | Out-File "X:\Mailbox Moves 
> > Master.csv"
> > -append
> > }
> > } 
> 
> .
> 
0
Utf
2/17/2010 10:56:01 AM
**Not tested**

$TargetDatabase = “SERVER01\SG03\MBX03”

$SourceFile = “x:\MAILMOVES.TXT”
$UserList = Get-Content $SourceFile

for($i=0;$i -lt $userlist.count;$i+=5){

$userlist=$userlist[$i..($i+4)]

#Start original foreach
ForEach ($user in $userlist)
{
$Date = Get-Date
Move-Mailbox $user  -TargetDatabase $TargetDatabase -baditemlimit 50
-PreserveMailboxSizeLimit:$False -Confirm:$False -ErrorAction
SilentlyContinue | ForEach {$Alias = $_.Alias; $SourceDatabase =
$_.SourceDatabase; $TargetDatabase = $_.TargetDatabase; $MailboxSize =
$_.MailboxSize; $StatusMessage = $_.StatusMessage; $StatusCode =
$_.StatusCode;

write-output "$Alias, $SourceDatabase, $TargetDatabase, $MailboxSize,
$StatusMessage, $StatusCode, $Date" | Out-File "X:\Mailbox Moves Master.csv"
-append
}
}
#End original foreach

} 

0
Marco
2/17/2010 12:02:57 PM
> for($i=0;$i -lt $userlist.count;$i+=5){
> 
> $userlist=$userlist[$i..($i+4)]
> 
> #Start original foreach
> ForEach ($user in $userlist)
> {

Oops!  The above won't exactly work.

Change to:
....
for($i=0;$i -lt $userlist.count;$i+=5){

$userlist_tmp=$userlist[$i..($i+4)]

#Start original foreach
ForEach ($user in $userlist_tmp)
{
.... 
0
Marco
2/17/2010 3:08:42 PM
Thanks for that Marco, I will try that and report back.

Many thanks Peter

"Marco Shaw [MVP]" wrote:

> > for($i=0;$i -lt $userlist.count;$i+=5){
> > 
> > $userlist=$userlist[$i..($i+4)]
> > 
> > #Start original foreach
> > ForEach ($user in $userlist)
> > {
> 
> Oops!  The above won't exactly work.
> 
> Change to:
> ....
> for($i=0;$i -lt $userlist.count;$i+=5){
> 
> $userlist_tmp=$userlist[$i..($i+4)]
> 
> #Start original foreach
> ForEach ($user in $userlist_tmp)
> {
> .... 
> .
> 
0
Utf
2/17/2010 4:15:01 PM
Check out the maxthreads parameter on move-mailbox cmdlet
-- 
Richard Siddaway
All scripts are supplied "as is" and with no warranty 
PowerShell MVP
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk


"Don Pedro" wrote:

> Hi all,
> 
> I created a script to move mailboxes and log the results. The script reads 
> the alias from a text file and moves the mailbox. When completed it logs the 
> result to a CSV file.
> 
> I would like to modify the script to move 5 mailboxes at a time and log the 
> results. I cannot seem to get it to work.
> 
> Below is the working script which allows one to move at a time. How can I 
> modify it to move 5 at a time AND to log the results to the CSV file.
> 
> ##############################################
> $TargetDatabase = “SERVER01\SG03\MBX03”
> 
> $SourceFile = “x:\MAILMOVES.TXT”
> $UserList = Get-Content $SourceFile
> 
> ForEach ($user in $userlist)		
> {
> $Date = Get-Date 
> Move-Mailbox $user  -TargetDatabase $TargetDatabase -baditemlimit 50  
> -PreserveMailboxSizeLimit:$False -Confirm:$False -ErrorAction 
> SilentlyContinue | ForEach {$Alias = $_.Alias; $SourceDatabase = 
> $_.SourceDatabase; $TargetDatabase = $_.TargetDatabase; $MailboxSize = 
> $_.MailboxSize; $StatusMessage = $_.StatusMessage; $StatusCode = 
> $_.StatusCode; 
>    	
> write-output "$Alias, $SourceDatabase, $TargetDatabase, $MailboxSize, 
> $StatusMessage, $StatusCode, $Date" | Out-File "X:\Mailbox Moves Master.csv" 
> -append	
> }
> }
0
Utf
2/17/2010 9:01:02 PM
Reply:

Similar Artilces:

Opening additional mailbox
I have an Exchange 2003 server, and my clients are all running Outlook 2003. A supervisor has requested access to a suboordinates e-mail box, so I added her (supervisor) with rights to that mailbox, and now inside of Outlook I can specify it to open the additional mailbox. The thing is, it is diplayed as so "Mailbox - User Name", and because these people work in an open workgroup type environment this box may be visible to people that look at her desktop. Can that be renamed? Named to display something else, or am I going about this all wrong. You cannot do that through Outlook...

Moving Mailboxes.
When moving mailboxes between 2 servers using the "move mailbox" command, is there a way to compress or zip up a large mailbox so that it does not take so long to move? Any help would be greatly appreciated. Roger Settle RSettle@klfinancialgroup.com "Roger Settle" <rsettle@klfinancialgroupREMOVETHIS.com> wrote: >When moving mailboxes between 2 servers using the "move >mailbox" command, is there a way to compress or zip up a >large mailbox so that it does not take so long to move? >Any help would be greatly appreciated. > >Roger S...

The Item could not be deleted. It was either moved or already deleted, or access was denied.
This is a multi-part message in MIME format. ------=_NextPart_000_0008_01C42C5B.11C3D7B0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I had to rebuild a corrupt database this morning. My Priv.edb and = Pub.edb were the files I worked on with the ESEUTIL. Everything is = working except users are complaining that they cannot delete e-mails = that were "zapped" during the rebuild process. The message they're = receiving is " The Item could not be deleted. It was either moved or = already deleted, or access was denied...

Last day of posting via Microsoft server
Well, I guess this is the last day of posting via the Microsoft server. http://www.teranews.com/ Your own free account ($3.95 one time setup fee) that allows posting or use public.teranews.com without an account (no posting & speed capped). You can use any standard news client you choose to read and post to any newsgroup. Or Google it: http://groups.google.com/groups/search?hl=en&q=microsoft.public.win98.gen_discussion&qt_s=Search God Bless America, Bill O|||||||O mailto:BillHughes@billhughes.com http://www.billhughes.com/jeep_bookmark.htm "D...

Disappearing emails from a shared mailbox
I set up a shared mailbox for one of our departments, and last night, when the mail user of it closed Outlook, the mails disappeared from the mailbox. I have logged directly onto the mailbox myself, and the historical mails are definitely not there. I have checked each users deleted items, and used the deleted items recovery tool in case one of them accidentally deleted the mails. all to no avail. whilst we can revoer from a backup tape, i would like to get to the bottom of how this has happened. has anyone had the same problem before? Check to see if 1 of the users had a archive or P...

private contacts moved to GAL DL's
I have a user who has many DL's in her private contacts, she wants to make them public in the GAL, what is the best method for this? We are using Exchange 5.5 and Outlook 2000. TIA, Nurv ...

exchange 5.5
I have a user who is getting emails addressed to another person in their mailbox. I checked the headers and the email was only addressed to person A (no cc's or bcc's), yet person B got it in their mailbox. What could be causing this? I have exchange 5.5 with SP 4 installed on a Windows 2000 Server. Jason: UserA most likely has some type of rule set up on his/her mailbox. Log on to UserA's mailbox with Outlook and check the rules. Also, there might be a setting on the mailbox itself that forwards message to UserB, so check the Delivery Options tab of UserA's mailbox prop...

reconnect to mailbox after Disabling user?
Hello, I was wondering if there is a easier way then to recycle the Exchange Services to renable a mailbox after a users mailbox has been disabled for x amount of time. I want to give access to this mailbox to another user so right now.. I simply go to Mailbox Rights -> (add the user I want to add) -> give allow rights to Read / Full but this requires a recycle of the services. Is there another way without recycling the services? G. On Mon, 23 Aug 2004 11:08:36 -0400, "Just Another Admin" <just@dmin.net> wrote: >Hello, > >I was wondering if there ...

Moving from cell to cell
Moving from cell to cell using arrow key stopped working. Help! Maybe hit Scroll Lock key... If Scroll Lock is on, the arrows still work, but in a different way. HTH Regards, Howard "crys0814" <crys0814@discussions.microsoft.com> wrote in message news:1B985BCA-BFB8-4718-8ED8-833BE78D8895@microsoft.com... > Moving from cell to cell using arrow key stopped working. Help! Hi there cry0814, It is possible that you have accidentally pressed your scroll lock key which disables your arrow keys. Try pressing it again and let us know your results Regard...

Changes Since Moving to Exchange
Hi there; I have subfolders within the inbox, and then subfolders within the subfolders. I also have rules so that when a message comes in from a certain person the message goes into their folder. Before we moved to our new exchange server if someone sent a message and the message went to their folder, the number of unread emails in the folder changes (ie, if Joe Bloggs sends an email to me his message goes to the Joe Bloggs folder, and it looks like Joe Bloggs (1)). And the folder that the 'Joe Bloggs' is in (for this example it could be 'staff') would also...

Can i move multiple lines between workbooks
I have a .csv format file listing speed cameras, and the different speeds are identified by two characters at the end of each line - 30, 40, 50 etc. I would like to create separate files for each speed, but Excel won't allow me to cut/copy several lines to created a new file/workbook. Is there any way round this? Martin Ellis Sun, 16 Sep 2007 03:28:00 -0700 from Martin Ellis <MartinEllis@discussions.microsoft.com>: > I have a .csv format file listing speed cameras, and the different speeds are > identified by two characters at the end of each line - 30, 40, 50 etc...

exchange 2003 mailbox access
Hi, Do you know how to access other users mailbox in exchange 2003? The account I am using is domain admin but I couldn't open users' mailbox under my login name. Is there any permissions I should assign? Thanks Char On Sun, 7 Aug 2005 18:27:05 -0700, "char" <char@discussions.microsoft.com> wrote: >Hi, > >Do you know how to access other users mailbox in exchange 2003? The account >I am using is domain admin but I couldn't open users' mailbox under my login >name. Is there any permissions I should assign? > >Thanks >Char By defau...

Suggestions for freeing up mailbox store space plan?
Hi all, I need to clean up mailbox stores on two exchange 2k3 ent servers . Here is our current exchange setup and 1st draft on plan: Setup-- Exchange 2k3 Ent (native mode/ No exchange SP) Server1 -- Win2k3 Ent w/SP1 Server2 -- Win2k3 Stnd w/SP1 Each server has four storage groups. Server 1 Storage groups come out to 160gbs and server 2 Storage groups come out to 145gbs. Each server has 4 mailbox stores and 1 pub folder store. The largest mailbox store on each server is 50gb. The other mailbox store sizes range from 8gbs to 20gbs. The pub folder store on each server is 70gbs. I can give...

Moving Exchange 2003 to new Hardware #2
I'm in the middle of my main server move.. this server is Primary Domain Controller, exchange 2003 server, DNS and DHCP hosts, AntiVirus (Symantec), and print server. This is on a Win2k3 sp 1 OS. I've moved Symantec first, that was easy. Now I'm moving Exchange 2003 - I've installed Exchange, both servers are now running the same version and I see both in the EMS. I've started to set the public folders to replicate from my oldserver to newserver.. The public folders replicated twice, and now stopped.. they are out of sync (I think this is related to a problem I'l...

Virus checking via double-clicking
Version: 2008 Operating System: Mac OS X 10.5 (Leopard) Processor: Intel At one time double clicking an Office file icon on the Mac by-passed virus checking. If I double click an Office file icon on my Mac, will Mac Office 2008 check for viruses automatically before opening the file for use by the Office application? On Tue, 2 Jun 2009 09:20:19 -0400, trying_to_work@officeformac.com wrote: > Version: 2008 > Operating System: Mac OS X 10.5 (Leopard) > Processor: Intel > > At one time double clicking an Office file icon on the Mac by-passed virus > checking. If I double cli...

How do I move Outlook Express Mail folders to new computer.
I am upgrading to a new computer. Both computers use Outlook Express 6.0. How can I move some of my mail folders to my new computer? Hi, Mike - This is a group to support Outlook from the Office group of programs. Outlook Express is a part of Internet Explorer and is a quite different program, despite its similar name.. You will probably get a faster and more expert answer if you post this to an Outlook Express news group. Try posting in one of these newsgroups: microsoft.public.windows.inetexplorer.ie5.outlookexpress for OE 5.x microsoft.public.windows.inetexplorer.ie55.outlookexpress...

Installing mailbox manager in Exch 5.5
I am trying to install Mailbox Manager in Exchange 5.5 and I keep getting the error "unable to install MBClean99 admin extension" during the install. Then the install fails. I cannot get past this. I am logged in as the exch service account and it definately has permissions to write to the "add-ins" directory. I have exch 5.5, sp4 on win2000 member server. thx, Clay Hilton http://support.microsoft.com/default.aspx?scid=kb;en-us;843495 On Fri, 29 Oct 2004 22:42:36 -0500, "Clay Hilton" <chilton@jam.rr.com> wrote: >I am trying to install Mailbox Ma...

How to purge all the Integration Manager log tables?
I went through and purged all the log files from Integration Manager using the procedure outlined in the IM User's Guide. However, after I was finished I looked at the tables in the im.mdb Access database and noticed that the following tables still have quite a few records in them: LogDocumentActivity LogActivity LogDocuments The Log table was empty, which makes sense since I purged all the logs. However, these other tables seem to have retained their records. Is there a way to purge these tables, too? -- Bud Cool, Accounting System Manager HDA, Inc. Hazelwood, MO GP 9.0, SP2 B...

finding a result
Is there something in Excel that you can compare contents of one Excel file with another file and output the differences? Myrna Larson and Bill Manville have developed a compare that's very nice. http://www.cpearson.com/excel/whatsnew.htm look for compare.xla But the bad news is that this does a cell-by-cell comparison. A1 compares to A1, x99 to x99, etc. If you insert/delete a row or column, then this won't work very well. Sam wrote: > > Is there something in Excel that you can compare contents > of one Excel file with another file and output the > differences? -...

Outlook 2007 with multiple mailboxes
I have a secretary that my manager wants to be able to see his emails. I set her up with his and her own account. The problem is when she replys or forwards the email, we want it to come from her email not his. Outlook 2007 is too smart and changes accounts when she forwards account so it looks like the manager has replied when the secretary has done on his behalf. You set her up as a DELEGATE and it is doing what you told it to do. If you only wanted to give her permission to see his inbox and calendar you should have set the permissions on the folders directly, and not use the "D...

Bulk Mailbox Reconnect
I am in a situation where I need to do a bulk mailbox restore onto a different Exchange server and I am a bit stuck. This is what I did, I will appreciate suggestions on what I may to resolve the issue or just a better way to do this. - Restored Information Store - Used CSVDE to export userlist from orginating AD - Modifed CSV to Removed all fields except for DN, objectClass, sAMAccountName - Modied DN to reflect destination AD - Used CSVDE to import userlist into destination AD - Enabled all imported users - Added Mailbox Stores to Mailbox Recovery - Matched mailboxes with usernames - Conne...

Difference in Mailbox Sizes
Hi, Can someone explain to me, why in Exchange System Manager a mailbox shows one particular size and when I look the properties of the mailbox in Outlook and view the folder size on the server tab it is quite a bit smaller? Thanks, Joe "Joe" <joe@response-it.co.uk> wrote in message news:%23CSDlRtsFHA.4072@TK2MSFTNGP09.phx.gbl... > Hi, > > Can someone explain to me, why in Exchange System Manager a mailbox shows > one particular size and when I look the properties of the mailbox in > Outlook and view the folder size on the server tab it is quite a bit ...

Intercompany (different currencies) bank transfers via GL
Hi there, I am trying to process bank transactions (cut checks) between two companies that have different functioning currencies (CAD and USD). I was able to accomplish this with a Payables Entry Transaction using the Distributions tab (and then posting Purchasing Series Batch and Financial Series Batch to send to destination company) but cannot replicate the same effect using a General Ledger Transaction. Can anyone please shed some light on this? TIA, Steve ...

reporting mailbox delegation ACLs using Powershell
Does anyone know of a way to retrieve the ACLs set on 2007 mailbox folders using Powershell? Say for example, user Joe has granted reviewer rights on his Inbox to Carla - I'd like to use Powershell to find and display that information. I've tried using the get-mailboxpermission and get-adpermission cmdlets but haven't found a way of retrieving them. Any help gratefully received... All the best, Darren ...

Multi-Search results into One Table
Hi All! I'm up for a bit of advice again!! You guys totally helped me out about a year ago! http://www.accessmonster.com/Uwe/Forum.aspx/access-forms/42886/Create-a-Search-using-Surnames-Firstnames-and-Invoice-Numbers#1163066276113601211570m73g2000cwdgooglegroupscom And now I'm up for some help again!! PLEASE!!! I have got a form which I need to search the following data: Surname - Fistname - Invoice Number. The search button I've got at the moment is a search textbox combined with the following query:- Like "*" & [Forms]![Search]![Search2] & "*" Re...