Solved

Mailbox movement script exchange 2007 powershell. get a error.

Posted on 2011-02-24
5
841 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
[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
  • 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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

626 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