Solved

Mailbox movement script exchange 2007 powershell. get a error.

Posted on 2011-02-24
5
837 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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

A procedure for exporting installed hotfix details of remote computers using powershell
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
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.

830 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