Solved

Mailbox movement script exchange 2007 powershell. get a error.

Posted on 2011-02-24
5
834 Views
Last Modified: 2012-05-11
Hi,

Mailbox movement script exchange 2007 powershell. get a error.

I get the below error

Get-Content : An object at the specified path C:\*20110225*.xml does not exist,
 or has been filtered by the -Include or -Exclude parameter.
At line:1 char:25
+ $EmailBody = get-content <<<<  "C:\*$date*.xml"
    + CategoryInfo          : ObjectNotFound: (System.String[]:String[]) [Get-
   Content], Exception
    + FullyQualifiedErrorId : ItemNotFound,Microsoft.PowerShell.Commands.GetCo
   ntentCommand

and this

Exception calling "Send" with "1" argument(s): "Failure sending mail."
At line:1 char:17
+ $smtpclient.Send <<<< ($mailmessage)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException


it works fine and does the job. Not sure whats that xml for and email does not work

regards
Raja
# NOTE: to run PowerShell scripts, you need to set the PS execution poloicy "set-executionpolicy unrestricted"

 

# load the list of users - this must be 1 user alias per line
# the user list file must be in the same directory as this script

 

$users = get-content MoveMbx1.txt

# move em to a specific target database using 10 threads

$users | move-mailbox -TargetDatabase "MailboxServer\StorageGroup01\MailboxStore01" -MaxThreads 10 -confirm:$false

 

# put today's date in a variable

$date=get-date -uformat "%Y%m%d"

 

# read today's migration log and store it as $EMailBody

$EmailBody = get-content "C:\*$date*.xml"

 

# when done, send us an email with the log text

$SmtpClient = new-object system.net.mail.smtpClient 
$MailMessage = New-Object system.net.mail.mailmessage 
$SmtpClient.Host = "smtpserver.domain.com" 
$mailmessage.from = ("<emailaddress>@domain.com") 
$mailmessage.To.add("<emailaddress>@domain.com") 
$mailmessage.Subject = “MoveMbx1.ps1 script has completed” 
$mailmessage.Body = $EmailBody 
$smtpclient.Send($mailmessage)

Open in new window

0
Comment
Question by:bsharath
  • 3
5 Comments
 
LVL 16

Expert Comment

by:Dale Harris
ID: 34977241
You're trying to find files with the $Date in the name I'm assuming.  Try this instead:

$Files = get-childitem "C:\" -filter "*$Date*.xml"

This will give you the list of files.  Then you can actually pick the first file or whatever you want:

$EmailBody = get-content $Files[0].fullname

Try that and see if it throws an error.

If you don't need it to search for files with different Dates, then I would just have it point to to a static file.

HTH,

Dale Harris
0
 
LVL 11

Author Comment

by:bsharath
ID: 34977274
Thanks
I am not sure why we need the xml

What i want is move 10 mailboxes at a time where the txt file will have 100's of ntlogins.

Email on every 10's completion with success and failure. If any line is not needed. please remove and give me just the code that's needed to run.
0
 
LVL 12

Accepted Solution

by:
prashanthd earned 500 total points
ID: 34977700
Mailbox-Move creates .xml and .log files when a mailbox is moved.

http://www.msexchange.org/articles_tutorials/exchange-server-2007/management-administration/moving-mailboxes-exchange-2007-part2.html

Confirm the path to the Migration log files which drive it is configured.

Instead of the .xml the email will contain the .log contents.

This will send a mail only after completion of all the mailbox moves.
# NOTE: to run PowerShell scripts, you need to set the PS execution poloicy "set-executionpolicy unrestricted"

# load the list of users - this must be 1 user alias per line
# the user list file must be in the same directory as this script

$users = get-content MoveMbx1.txt

# move em to a specific target database using 10 threads

$users | move-mailbox -TargetDatabase "MailboxServer\StorageGroup01\MailboxStore01" -MaxThreads 10 -confirm:$false

# put today's date in a variable

$date=get-date -uformat "%Y%m%d"

# read today's migration log and store it as $EMailBody

$EmailBody = get-content "C:\Program Files\Microsoft\Exchange Server\Logging\MigrationLogs\*$date*.log"

# when done, send us an email with the log text

$SmtpClient = new-object system.net.mail.smtpClient 
$MailMessage = New-Object system.net.mail.mailmessage 
$SmtpClient.Host = "smtpserver.domain.com" 
$mailmessage.from = ("<emailaddress>@domain.com") 
$mailmessage.To.add("<emailaddress>@domain.com") 
$mailmessage.Subject = “MoveMbx1.ps1 script has completed” 
$mailmessage.Body = $EmailBody 
$smtpclient.Send($mailmessage)

Open in new window

0
 
LVL 12

Expert Comment

by:prashanthd
ID: 34977717
Also change the following line no 26
$mailmessage.To.add("<emailaddress>@domain.com")

to
$mailmessage.To = ("<emailaddress>@domain.com")
0
 
LVL 12

Expert Comment

by:prashanthd
ID: 35015704
Hi,

Have you tried this code?
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The article will show you how you can maintain a simple logfile of all Startup and Shutdown events on Windows servers and desktops with PowerShell. The script can be easily adapted into doing more like gracefully silencing/updating your monitoring s…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

757 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

19 Experts available now in Live!

Get 1:1 Help Now