PowerShell Display Table In HTML Email

后端 未结 7 2379
春和景丽
春和景丽 2021-01-02 12:17

Ok, this may have been answered, but I\'m new and trying to learn, so I guess I\'m not \"getting\" it. I have a variable that contains a table of information (I got it from

7条回答
  •  孤独总比滥情好
    2021-01-02 12:29

    I use like this:

    Import-Module C:\dbatools\dbatools.psd1
    
    $HostName = Get-WMIObject Win32_ComputerSystem | Select-Object -ExpandProperty name
    $DiskResult = Get-DbaDiskSpace -ComputerName $HostName | Sort-Object $_.FreeInGB | Out-DbaDataTable
    
    # Create column headers of Table1
    $HtmlTable1 = ""
    
    # Insert data into Table1
    foreach ($row in $DiskResult)
    { 
        $HtmlTable1 += ""
    }
    $HtmlTable1 += "
    ComputerName Name Label SizeInGB FreeInGB PercentFree
    " + $row.ComputerName + " " + $row.Name + " " + $row.Label + " " + $row.SizeInGB + " " + $row.FreeInGB + " " + $row.PercentFree + "
    " # Send Mail Inputs $smtpserver = "smtp.domain.com" $from = "Powershell Mail <" + $HostName + "@domain.com>" $to = "", "" $cc = "" , "" $subject = "Disk Check for SQL Server" $body = "Disk info for SQL Server like below:

    " + $HtmlTable1 Send-MailMessage -smtpserver $smtpserver -from $from -to $to -cc $cc -subject $subject -body $body -bodyashtml

提交回复
热议问题