Monthly Archive


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,            
 [ValidateSet("C", "F", "K")]            
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            

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