Email Success or failure of new-moverequest

  • Thread starter cjstrads
  • Start date Views 1,272
Status
Not open for further replies.
C

cjstrads

Hi,

I'm trying to find a way to send an automated email once a scripted 'new-moverequest' completes. We're moving 10 users at a time and would like to automate it so we don't need to manually check the logs\console to ensure completion.

I was thinking that using the Send-MailMessage feature could play a part but I'm not sure how I can get the script to read if the move was successful or not and then trigger the email. Has anyone achieved this?

Thanks
 
M

Mike Crowley [MVP]

You want to be notified when a move request fails? You could schedule frequently reoccurring a task which runs something like this

Get-MoveRequest | where {$_.status -ne 'completed'} | Out-File c:\IncompleteMoveRequests.csv

then use the csv as an attachment in the send-mailmessage command.

Mike Crowley
Check out My Blog!
 
A

Alexei Segundo

Something like this for the send part:
$expfile = " c:\IncompleteMoveRequests.csv" $smtpServer = " smtp.contoso.com" $msg = new-object Net.Mail.MailMessage $att = new-object Net.Mail.Attachment($expfile) $smtp = new-object Net.Mail.SmtpClient($smtpServer) $msg.From = " moves@contoso.com" $msg.To.Add(" support@contoso.com" ) $msg.Subject = " Incomplete Move Requests Found" $msg.Body = " Please see the attached report showing failed move requests" $msg.Attachments.Add($att) $smtp.Send($msg) $att.Dispose()
Alexei
 
C

cjstrads

I need a message sent that lists those that completed successfully and those that failed.

I guess the scheduled task approach could do it but what I was hoping to do was link it to the current script that performed the move request.

Thanks.
 
N

Neil Hobson

I did this with Exchange 2007 and the Move-Mailbox cmdlet as it was possible to obtain the status code of each mailbox moved and, if the status was 0 (success), an email was sent to welcome the user to Exchange 2007. However, things have changed somewhat in Exchange 2010 as you know. I think you need to draw on Mike's example but I think this could be tricky. For example, at the end of the script that creates the move requests, get a list of the requests via the Get-MoveRequest cmdlet and for any that have a status of 'completed' send an email and then remove the move request. Loop round again until all move requests are gone. You'll need to remove the move requests after sending an email otherwise they'll get multiple emails. Needs a lab and a bit of development. :)Neil Hobson Principal Consultant, Silversands www.silversands.co.uk www.msexchange.org/neil_hobson
 
G

Gavin-Zhang

Hi Cjstrads,
Above gave some good suggestion, other cmdlets you could make a test:
get-moverequest |sort-object -property status |select-object identity,status |out-file c:\movestatus.txt
The cmdlets would list the main information that your want.
And then you would use send-mailmessage windows powershell to send a mail to someone.
Other information for you:
http://technet.microsoft.com/en-us/library/dd347693.aspx
Regards!
Gavin
 
Status
Not open for further replies.
Top