Render SSRS Report with parameters using SOAP in Powershell

前端 未结 3 1434
别那么骄傲
别那么骄傲 2021-01-03 08:23

I\'ve been toying with this for days with no luck. Essentially I\'m trying to build a simple library to render SSRS reports using Powershell. I\'m using Powershell in an a

3条回答
  •  既然无缘
    2021-01-03 09:01

    Had the same issue, furthermore wanted to send the generated MHT file as an email body: The following was found to work The old CDO.Message is the only thing I found that allows sending a MHTML file as an email body. Below is a (working) translation of a VB program Old but simple ;-)!

    ################## Send MHTML email ##############################
    # use antiquated CDO to send mhtml as email body
    
    $smtpServer = "my-mail-server"
    $smtpSubject = "MHT file sent as body of email"
    $smtpTo = "you@work.com"
    $smtpFrom = "me@home.org"
    $MHTMLfile = "my-MHT-File.mht
    # e.g. from an SSRS.Render
    
    
    $AdoDbStream = New-Object -ComObject ADODB.Stream
    $AdoDbStream.Charset = "ascii"
    $AdoDbStream.Open()
    $AdoDbStream.LoadFromFile($MHTMLfile)
    $CdoMessage = New-Object -ComObject CDO.Message
    $CdoMessage.DataSource.OpenObject($AdoDbStream,"_Stream")
    
    $SendUsingPort = 2
    $smtpPort = 25
    
    $cfg = "http://schemas.microsoft.com/cdo/configuration/"
    $CdoMessage.Configuration.Fields.Item($cfg + "sendusing") =  $SendUsingPort
    $CdoMessage.Configuration.Fields.Item($cfg + "smtpserver") = $SmtpServer
    $CdoMessage.Configuration.Fields.Item($cfg + "smtpserverport") = $smtpPort 
    
    $CdoMessage.To      = $smtpTo
    $CdoMessage.From    = $smtpFrom
    $CdoMessage.Subject = $smtpSubject
    
    $CdoMessage.MimeFormatted = $true
    $CdoMessage.Configuration.Fields.Update()
    
    WRITE-HOST "Sending email"
    $CdoMessage.Send()
    

提交回复
热议问题