Based on another question I posted on here, I was able to get the majority of this script working, but I don’t know how to change the formatting of a select-object. Google has been no help.
$head = @'
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Current Conditions</title>
</head>
<body style="background-color:#EEEEEE">
<h3 style="margin:0;padding-bottom:3px">Current Conditions at
'@
$1 = @'
</h3>
<p style="margin:0;padding-bottom:0px"><b>Dewpoint: </b>
'@
$2 = @'
</p>
<p style="margin:0;padding-bottom:0px"><b>Temperature: </b>
'@
$3 = @'
</p>
<p style="margin:0;padding-bottom:3px"><b>Humidity: </b>
'@
$end = @'
</p>
</body>
</html>
'@
$info = import-csv 1-pastweek.csv
$time = $info | select -last 1 Time
$temp = $info | select -last 1 Temp
$humid = $info | select -last 1 Humid
$dewpt = $info | select -last 1 Dewpt
$head + $time + $1 + $dewpt + $2 + $temp + $3 + $humid + $end | out-file -encoding "UTF8" current.html
This does work, but the format of the html output includes the header info from the CSV and I don’t see how to get around it.
Current Conditions at @{TIME=03/12/2012 15:32:22}
Dewpoint: @{DEWPT=62.7}
Temperature: @{TEMP=71.9}
Humidity: @{HUMID=74.4}
Any ideas on how to get the @{HEADER } to go away. I only want the actual data.
For what you were trying, you just had to add
-expandpropertyto get the actual value rather than objects with the property.For example:
and you can use
$timedirectly, rather than$time.TIMEAlso, if this is all you are doing and you are going to use the
$time.TIMEetc. you could have done:and used
$info.Timeetc.