Solved

Mailbox movement script exchange 2007 powershell. get a error.

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
exchange ,script 10 43
powershell $webclient.UploadFileWithUniqueName 6 24
Powershell replace german characters in string 12 27
set-aduser powershell command issue 2 28
This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

770 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