PowerShell Display Table In HTML Email

后端 未结 7 2321
春和景丽
春和景丽 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:45

    For someone looking for a simple table,here is what i have found

    add below variable first

    $Header = @"
    
    "@
    

    You can add like below then

    Get-PSDrive | ConvertTo-Html -Property Name,Used,Provider,Root,
    CurrentLocation 
    -Head $Header | Out-File -FilePath PSDrives.html
    

    While reading the file,ensure you use -raw as a parameter like bellow

    Get-ChildItem Cert:\LocalMachine\My  | Where-Object {$_.NotAfter -ge (get-date -DisplayHint Date) } |ConvertTo-Html -Property Issuer,Thumbprint,Notafter -Head $Header | Out-File C:\Iris\Cert.html
    $body=Get-Content -Path C:\Iris\cert.html -Raw
    

    then while sending mail, you can do

    send-emailmessage -body $body -bodyashtml #other values
    

    References:
    https://4sysops.com/archives/building-html-reports-in-powershell-with-convertto-html/

提交回复
热议问题