Declaring parameters and combining them

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.


#adding a function to script and describing functionality of function and its parameters.

function Get-DisksSPaceReport {
$ComputerName = $env:COMPUTERNAME)
process {
$diskList = get-wmiobject Win32_LogicalDisk -Filter “DriveType = 3”
foreach ($disk in $diskList){
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’;


‘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’;


‘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’;

Driver Status

@{Name=‘Capacity’;Expression={[math]::round($.Size / 1GB,2)}},
.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
$wsh.popup(" HTML report is ready. Please check it in chrome browser",10,“Powershell Automation”,0+64)


Try being a little clearer on what exactly is or is not working, but are you referring to setting the same parameters over and over again? The splatting of parameters is using hash tables, so you can look at managing hash tables to .Add parameters, .Remove parameters or Setting (.Set_Item) on a parameter to leverage a one parameter set and manipulate it.

#Define original params
$params = @{
    'PreContent'='SERVIS LOGS';
    'Properties'='Displayname','Name',@{n='Service Status';e={$_.Status};css={if ($_.Status -eq "Stopped") { 'red' } else {'green'}}}

'First parameter...'

'Update the PreContent key...'
$params.Set_Item('PreContent', 'Next Header')

'Second parameter...'


PS C:\Users\rasim\Desktop> C:\Users\rasim\Desktop\test.ps1
First parameter...
Update the PreContent key...
Second parameter...
Next Header