Hello
I just started to play around HTML outputs in Powershell and when i read those cmdlets and parameters, my eyes are bleeding as yours will be. My point is that there are some parameters to combine some parameters but i couldn’t figure out how. I think that i shouldn’t declare parameters for every case.
Ps: and Yes, i copied some cmdlets from here but i am just learner.
[pre]
#adding a function to script and describing functionality of function and its parameters.
function Get-DisksSPaceReport {
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline=$true)]
[ValidateNotNullOrEmpty()]
[System.String]
$ComputerName = $env:COMPUTERNAME)
process {
$diskList = get-wmiobject Win32_LogicalDisk -Filter “DriveType = 3”
foreach ($disk in $diskList){
[PSCustomObject]@{
ComputerName = $disk.PSComputerName
DriveLetter = $disk.DeviceID
VolumeName = $disk.VolumeName
Size = $disk.Size
FreeSpace = $disk.FreeSpace }}}}
$date = get-date
#params directing inputs and variables as HTML outputs according to css.
$params = @{‘As’=‘Table’;
‘PreContent’=‘
SERVIS LOGS
’;‘MakeTableDynamic’=$true;
‘TableCssClass’=‘grid’;
‘Properties’=‘DIsplayname’,‘name’,@{n=‘Service Status’;e={$.Status};css={if ($.Status -eq “Stopped”) { ‘red’ } else {‘green’}}}}
#the google services are converted to HTML according to @params
$SPservice = Get-Service -Displayname “google” | ConvertTo-EnhancedHTMLFragment @params
$params2 = @{‘As’=‘Table’;
‘PreContent’=‘
EVENT LOGS
’;‘MakeTableDynamic’=$true;
‘TableCssClass’=‘grid’;
‘Properties’=‘instanceID’, @{n=‘Entry Status’;e={$.Entrytype};css={if ($.entrytype -eq “warning”) { ‘red’ } else {‘orange’}}}}
$eventlogs = Get-EventLog System -Newest 25 | ConvertTo-EnhancedHTMLFragment @params2
#params3 declares different values than other params. COnverting capacity and Freespaceses in GB instead of bytes. With if statements, declaring which color they will be assigned by css.
$params3 = @{‘As’=‘Table’;
‘PreContent’=‘
Driver Status
’;‘MakeTableDynamic’=$true;
‘TableCssClass’=‘grid’;
‘Properties’=‘Computername’,‘DriveLetter’,
@{Name=‘Capacity’;Expression={[math]::round($.Size / 1GB,2)}},
@{Name=‘FreeSpaceIn%’;Expression={[math]::round($.FreeSpace / $.Size * 100,2)};css={if ($.Free -gt 100) { 'red '} else {‘green’}}},
@{Name=‘FreeSpaceLessThan10%’;Expression={If(($.FreeSpace / $.Size * 100) -lt 10){$true}Else{$false}}},
@{Name=‘FreeSpace’;Expression={[math]::round($.FreeSpace / 1GB,2)}; css={if ($.Free -gt 100) { 'red '} else {‘green’}}}}
#getting driver objects
$drivers= Get-DisksSPaceReport| Select-Object -Property ComputerName,DriveLetter,VolumeName,Size,FreeSpace | ConvertTo-EnhancedHTMLFragment @params3
#getting all variables in HTML format and applying CSS file and creating a txt file in a particular file.
ConvertTo-EnhancedHTML -HTMLFragments " $SPservice $eventlogs $Drivers $date" -CssUri C:\Users\A701026\Desktop\sample\styles2.css |Out-File C:\Users\A701026\Desktop\sample\paramexample.html
#creating pop up which shows a warning related with result.
$wsh = new-object -com wscript.shell
$wsh.popup.overloaddefinitions
$wsh.popup(" HTML report is ready. Please check it in chrome browser",10,“Powershell Automation”,0+64)
[/pre]