powershell - output dtexec result to email
Good morning, I'm sorry. I know this is not the proper forum but I've been looking for the scripting guy forums without success in the list of forums to post to. The SSIS forum was the closest I could get to my problem. It would be nice if it could be moved to its proper forum. I got the following piece of code: $v_dtsxFile = "D:\dtsx\Dim_Language_Load.dtsx" $v_dtexecarguments = "/f $v_dtsxFile /de agoda /set \Package.Variables[User::v_batchid].Properties[Value];`"$v_batchid`" /set \Package.Variables[User::v_jobid].Properties[Value];`"$v_jobid`" /set \Package.Variables[User::v_taskid].Properties[Vaue];`"$v_taskid`"" C:\"Program Files"\"Microsoft SQL Server"\100\DTS\Binn\dtexec $v_dtexecarguments | out-string -outvariable $ssisResults if ($LASTEXITCODE -eq 0) { #Success log-taskend -v_logid $v_logid -v_batchid $v_batchid -v_jobid $v_jobid -v_taskid $v_taskid -v_status "'SUCCESS'" -v_conn $v_conn -v_error "NULL" } else { #failure log-taskend -v_logid $v_logid -v_batchid $v_batchid -v_jobid $v_jobid -v_taskid $v_taskid -v_status "'FAILED'" -v_conn $v_conn $subject = "Dim_Language_Load.dtsx failed jobid: $v_jobid, batchid: $v_batchid" $to = "firstname.lastname@domain.com" $from = "someone@domain.com" Send-Email $ssisResults $subject $to $from exit } What I'm trying to achieve is send dtexec output by email in case of failure. The whole process works pretty well at the exception of the email sending. I've tried piping it out to a variable using out-string the way I do here but in case of failure I get no results in my email. It pipes to a text file no problem. I got a mail function that looks like this that I use to send email in case of errors. function Send-Email { param ( [string]$message, [string]$subject, [string]$to, [string]$from ) $SmtpClient = new-object system.net.mail.smtpClient $MailMessage = New-Object system.net.mail.mailmessage $SmtpClient.Host = "mail2.hkg.agoda.local" $mailmessage.from = ($from) $mailmessage.To.add($to) $mailmessage.Subject = $subject $mailmessage.Body = $message $smtpclient.Send($mailmessage) } If someone could guide me through this, it would be really great. thanks in advance. Nico
August 31st, 2009 10:32am

Hi,Do u have an option of modifying the package?You could setup a send mail task on the onError event to send mail in case there is any failure.Hope this helps !! Please close the threads once answered - Sudeep
Free Windows Admin Tool Kit Click here and download it now
August 31st, 2009 11:53am

What is the version of powershell you have? If it is v3 or v2 you can use Send-MailMessage cmdlet Check the return value of $HostPlease vote as helpful or mark as answer, if it helps Cheers, Raunak | t: @raunakjhawar | My Blog
January 9th, 2013 8:28am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics