Suresh Kumar
asked on
Need to add another Column in Powershell script output
[cmdletbinding()]
param
(
[string[]$ComputerName = $env:ComputerName
)
$cpuload = ((Get-Counter -Counter "\\$ComputerName\Process(* )\% Processor Time" -ea 0).CounterSamples) | Select-Object -Property instancename, cookedvalue | Sort-Object -Property cookedvalue -Descending | Select-Object -First 5
$a = @'
<style type='text/css'> .nxn-ret-table{width:100%; border-collapse:collapse; font-family: Arial;} /* Define the background color for all the ODD background rows */ .nxn-ret-table tr:nth-child(odd){ background: #DAE0E1;} /* Define the background color for all the EVEN background rows */ .nxn-ret-table tr:nth-child(even){backgro und: #f7f7f7; } pre { font-family: Arial; overflow: auto;} </style>
'@
$cpuload | ConvertTo-Html -head $a -body "<H2>CPU LOAD</H2>" | Out-File -FilePath C:\tmp\disk.txt
Get-Content 'C:\tmp\disk.txt' | Foreach-Object {$_ -replace '<table>', ("<table class='nxn-ret-table'>")} | Foreach-Object {$_ -replace '^<html.*$', ("<html>")} | Set-Content 'C:\tmp\disk1.txt'
cat C:\tmp\disk1.txt
When i run the above script,the ouput looks like
CPU LOAD
InstanceName CookedValue
_total 201.321060012225
idle 192.100248103268
powershell_ise 4.61040595447844
system 1.53680198482615
iexplore 0
I need to add another row showing thier CPU usage in %
i.e CPU usage =Cooked Value/_total*100
Ouptut should be like
CPU LOAD
InstanceName CookedValue CPU %
_total 201.321060012225
idle 192.100248103268 =Cooked Value/_total*100
powershell_ise 4.61040595447844
system 1.53680198482615
iexplore 0
param
(
[string[]$ComputerName = $env:ComputerName
)
$cpuload = ((Get-Counter -Counter "\\$ComputerName\Process(*
$a = @'
<style type='text/css'> .nxn-ret-table{width:100%;
'@
$cpuload | ConvertTo-Html -head $a -body "<H2>CPU LOAD</H2>" | Out-File -FilePath C:\tmp\disk.txt
Get-Content 'C:\tmp\disk.txt' | Foreach-Object {$_ -replace '<table>', ("<table class='nxn-ret-table'>")} | Foreach-Object {$_ -replace '^<html.*$', ("<html>")} | Set-Content 'C:\tmp\disk1.txt'
cat C:\tmp\disk1.txt
When i run the above script,the ouput looks like
CPU LOAD
InstanceName CookedValue
_total 201.321060012225
idle 192.100248103268
powershell_ise 4.61040595447844
system 1.53680198482615
iexplore 0
I need to add another row showing thier CPU usage in %
i.e CPU usage =Cooked Value/_total*100
Ouptut should be like
CPU LOAD
InstanceName CookedValue CPU %
_total 201.321060012225
idle 192.100248103268 =Cooked Value/_total*100
powershell_ise 4.61040595447844
system 1.53680198482615
iexplore 0
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER