Categories

Temperature conversion charts

The temperature conversion function we created last time can be used to create a conversion chart.

function new-temperaturechart {            
param (            
 [int]$start = -10,            
 [int]$end = 30,            
             
 [parameter(Mandatory=$true)]            
 [string]            
 [ValidateSet("C", "F", "K")]            
 $inputTemp            
            
)            
            
if ($start -ge $end){Throw "End temperature must be greater than starting temperature"}            
            
$start..$end |             
foreach {            
 $point = New-Object -TypeName PSObject -Property @{            
  F = convert-temperature -temperature $_ -inputTemp $inputTemp -outputTemp F            
  C = convert-temperature -temperature $_ -inputTemp $inputTemp -outputTemp C            
  K = convert-temperature -temperature $_ -inputTemp $inputTemp -outputTemp K            
 }            
 $point            
}              
            
}


Simply set the start and end points and which temperature scale the input relates to. An object is created with values for F, C and K for each of the input points.



PowerShell isn’t just for the difficult – it helps with the simple things as well

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>