Powershell script to get Output to html format in body of the e-mail

Tagged: 

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Venkata Kalyan Venkata Kalyan 7 months ago.

  • Author
    Posts
  • #38204
    Profile photo of Venkata Kalyan
    Venkata Kalyan
    Participant

    Hi,
    I have a csv file, which has information like below (columns):
    Name Datastore Folder
    DSFPRDDB18_Replica dr-lun11-APP-vm VM
    DSFPRDAPP182_Replica dr-lun16-APP-vm,dr-lun207-DB-vm VM

    I wrote a .vbs script, but it is not working as expected. I am looking a for a powershell script which can will give me desired output.

    I am looking for (ex: name has PRD, datastore has APP & name had DB, datastore has PRD, it should mail information. Same way, it should go through complete .CSV file and give me the output. If all the fields are mapped correclty, it should say: ALL GOOD.

    .vbs script what I wrote:
    strExcelPath = "C:\Opscripts\Kalyan\Vranger_Scripts\Lun_Check\Lun_Mapping_Wrong.csv"
    set objexcel= createobject("Excel.Application")
    objexcel.visible=False
    Set objWorkBook=objExcel.WorkBooks.Open(strExcelPath)

    intRow= objWorkBook.Worksheets(1).UsedRange.Rows.count
    objWorkBook.Worksheets(1).Range("D:D").ClearContents
    objWorkBook.Worksheets(1).cells(1,4) = "Results"
    objexcel.DisplayAlerts =false

    'To get the Column Values of the Fields
    For i = 1 to intRow
    if (instr(ucase(objWorkBook.Worksheets(1).Cells(i, 1)),"APP") and instr(ucase(objWorkBook.Worksheets(1).Cells(i, 2)),"DB")) Then
    objWorkBook.Worksheets(1).Cells(i, 4) = "Error. Please check"
    End if

    if (instr(ucase(objWorkBook.Worksheets(1).Cells(i, 1)),"DB") and instr(ucase(objWorkBook.Worksheets(1).Cells(i, 2)),"APP")) Then
    objWorkBook.Worksheets(1).Cells(i, 4) = "Error. Please check"
    End If
    Next
    objWorkBook.Save
    objWorkBook.Close
    Set objexcel = nothing

    -Kalyan

  • #38214
    Profile photo of Curtis Smith
    Curtis Smith
    Participant

    @venkata-kalyan
    Show what you've tried in powershell and what is not working and we can try and help out. If you have not tried in powershell, give it a shot first.

    Here are some of the powershell cmdlets I believe would be very helpful for this effort:
    Import-CSV
    Where-Object
    ConvertTo-HTML
    Send-MailMessage

  • #38670
    Profile photo of Venkata Kalyan
    Venkata Kalyan
    Participant

    Thanks. It worked out.

    -Kalyan

You must be logged in to reply to this topic.