i'm using powershell script transfer data html file. need add line numbers automatically(lp) , change color of cell(sum/gb) depending on value. if less 20 -do nothing, when more 20 , less 25 - yellow, when more 25 -red .
my script:
$a = '<style>' $a = $a + 'body{background-color:peachpuff;}' $a = $a + 'table{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}' $a = $a + 'th{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}' $a = $a + 'td{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:palegoldenrod}' $a = $a + '</style>' [int]$c=0 [int]$d=20 [int]$e=25 $computers | sort-object usersurname | where-object {($psitem.username -ne '' -and $psitem.usersurname -ne '')}| select-object -property @{n='lp';e=$psitem.index}},` @{n='surname';e=$psitem.usersurname}},` @{n='name';e={$psitem.username}},` @{n='desktop/gb';e={'{0:n2}' -f $psitem.hddusagedesktop/1gb)}},` @{n='documents/gb';e={'{0:n2}' -f($psitem.hddusagedocuments/1gb)}},` @{n='pictures/gb';e={'{0:n2}' -f($psitem.hddusagepictures/1gb)}},` @{n='video/gb';e={'{0:n2}' -f($psitem.hddusagevideos/1gb)}} ,` @{n='sum/gb';e={'{0:n2}' -f($psitem.hddusage/1gb)}},` @{n='size hdd/gb';e={$psitem.hddsize}},` @{n='free space/gb';e={$psitem.freespace}},` @{n='fre space/%';e={$psitem.percentofthespaceusage}},` @{n='last scan date';e={$psitem.lastscandate}},` @{n='adsress ip';e={$psitem.ipv4}} | foreach-object {if(([convert]::toint16($psitem.hddusage)-ge $d) -and ([convert]::toint16($psitem.hddusage)-lt $e) ){$psitem -replace '<tr>','<tr bgcolor=green>'}elseif([convert]::toint16($psitem.hddusage) -ge $e ){$_ -replace '<tr>','<tr bgcolor=red>'}else{$_}} | convertto-html -body '<h2>hdd usage</h2>' -head $a | out-file c:\users\adminrka\desktop\report.html
output:
Comments
Post a Comment