knowledge base


Powershell HTML Export


  • PS2HTML Report


  • PSH2HTML Beispiel
    set-executionpolicy unrestricted Remove-Item "C:\temp\result.html" $htmlhead="<html> <style> BODY{font-family: Arial; font-size: 10pt;} H1{font-size: 16px;} H2{font-size: 14px;} H3{font-size: 12px;} TABLE{border: 1px solid black; border-collapse: collapse; font-size: 10pt;} TH{border: 1px solid black; background: #dddddd; padding: 5px; color: #000000;} TD{border: 1px solid black; padding: 5px; } td.pass{background: #7FFF00;} td.warn{background: #FFE600;} td.fail{background: #FF0000; color: #ffffff;} td.info{background: #85D4FF;} </style> <body> <div style='margin: 0px auto; BACKGROUND-COLOR:Black;Color:White;font-weight:bold;FONT-SIZE: 16pt;TEXT-ALIGN: center;'> Services Report $Env:Computername</div>" $Win32_OperatingSystem = Get-WmiObject -class Win32_OperatingSystem | Select-Object -property Caption,BuildNumber,Version, ServicePackMajorVersion,Manufacturer,OSArchitecture, @{n='LastBootTime';e={$_.ConvertToDateTime($_.LastBootUpTime)}} | ConvertTo-HTML $DBData = dir SQLSERVER:\SQL\INSTANZ\DEFAULT\Databases | Select Name, Size, SpaceAvailable, DataSpaceUsage, IndexSpaceUsage, RecoveryModel, LastBackupDate, LastLogBackupDate | ConvertTo-HTML -Body "$htmlreport" -Title "Server Status" cd SQLSERVER:\SQL\INSTANZ\DEFAULT\JobServer\Jobs $DBData3 = Get-ChildItem | select Name, LastRunDate, NextRunDate | ConvertTo-HTML $Disks = Get-WMIObject Win32_LogicalDisk | Where-Object {$_.DriveType -eq 3} | select DeviceID, @{Name='SizeGB';Expression= {$_.Size / 1GB}}, @{Name='FreeGB';Expression={$_.FreeSpace / 1GB }} | ConvertTo-HTML $DATA = ls I:\VERZEICHNIS\Data\*.mdf | select name, @{Name="MB";Expression={$_.Length / 1Mb}} | ConvertTo-HTML $LOG = ls J:\VERZEICHNIS\Log\*.ldf | select name, @{Name="MB";Expression={$_.Length / 1Mb}} | ConvertTo-HTML $Services = Get-service *SQL* | Where-Object {$_.status -eq "Running"} | select ServiceName, Status | ConvertTo-HTML $EVSYS = "<h3>&nbsp;&nbsp;Eventlog APPLICATION (last 10)</h3><br>" $EventSystem = Get-EventLog -newest 10 -LogName "application" | Where-Object {$_.source -like "*SQL*"} | ConvertTo-HTML $EVAPP = "<h3>&nbsp;&nbsp;Eventlog SYSTEM (last 10)</h3><br>" $EventApplic = Get-EventLog -newest 10 -LogName "system" | ConvertTo-HTML $footer = "<h3>&nbsp;&nbsp;(c) 09.10.2017 by IT-FRICKE</blockquote></h3></body></html>" $htmlreport = $htmlhead + $htmlreport + $Win32_OperatingSystem + $htmltail + $DBData + $DBData3 + $Disks + $DATA + $LOG + $Services + $EVSYS + $EventSystem + $EVAPP + $EventApplic + $footer | Out-File -Encoding utf8 "C:\temp\result.html" cd c:\windows\system32 [system.Diagnostics.Process]::Start("iexplore","C:\temp\result.html")