Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Mailbox movement script exchange 2007 powershell. get a error.

Posted on 2011-02-24
5
Medium Priority
?
845 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 2000 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
A walk-through example of how to obtain and apply new DID phone numbers to your cloud PBX enabled users that are configured in Office 365. Whether you have 1, 10 or 100+ users in your tenant, it's quite easy to get them phone-enabled and making/rece…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Suggested Courses
Course of the Month13 days, 8 hours left to enroll

963 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