This blog has moved to http://ThePowerShellGuy.com
Greetings /\/\o\/\/
Getting a clock Counting down the time till new Year,
and giving the current day and time.
Enjoy and Best wishes for 2006
/\/\o\/\/
# Clock.msh
# gives time till NewYear and clock
# /\/\o\/\/ 2005
function Main {
$pos = $host.ui.rawui.windowposition
$size = $host.ui.rawui.buffersize
$rect = "system.management.automation.host.rectangle"
$posOld = $pos
$re = new-object $rect $pos.x,$pos.y,$size.width,($pos.y + 10)
$buffer = $host.ui.rawui.getbuffercontents($re)
While (!$host.ui.rawui.KeyAvailable) {
$pos = $posOld
([datetime]"1-1-2006").Subtract((get-date)).tostring().Substring(0,([datetime]"1-1-2006").Subtract((get-date)).tostring().LastIndexOf(".")).getEnumerator() | foreach {
DrawNum $_ "Red"
$pos.x += 4
}
$pos.Y += 6 ; $pos.x = 0
((get-date)).tostring("dd-MM HH:mm").getEnumerator() | foreach {
DrawNum $_ "Green"
$pos.x += 4
}
sleep 1
}
$host.ui.rawui.SetBufferContents($posOld,$buffer)
}
Function DrawNum ($num = 0 ,$color){
Switch($Num){
0 {$ia = (367,61)}
1 {$ia = (292,36)}
2 {$ia = (487,57)}
3 {$ia = (487,60)}
4 {$ia = (493,36)}
5 {$ia = (463,60)}
6 {$ia = (463,61)}
7 {$ia = (295,36)}
8 {$ia = (495,61)}
9 {$ia = (495,60)}
":" {$ia = (16,2)}
"." {$ia = (0,2)}
" " {$ia = (0,16)}
"-" {$ia = (448,0)}
}
$row = ""
foreach ($int in $ia) {
0..8 | foreach {
if ($int -band [math]::pow(2,$_)) {$row += [char]9608} else {$row +=" "}
if (($_ +1)%3 -eq 0) {$row += "`n"}
}
}
$Buf = $host.ui.rawui.NewBufferCellArray(($row.trimEnd().Split("`n")),[System.ConsoleColor]$color,"black")
$host.ui.rawui.SetBufferContents($pos,$buf)
}
. main