You are on page 1of 2

#

#Leapyear.ps1, version 1.00


#
#usage: .\leapyear.ps1 [year]
#
#where: "year" is the year which you want to test
# (default is current year)
#
#written by Rob Van Der Woude
#http://www.robvanderwoude.com
#

#get the specified year


Param ([int] $year=(get-date).year)

#get the current year


[Int] $thisyear=(get-date).year

#format the output text (past, presnt or future)


$is1="is"
$is2=""
If($year -lt $thisyear) {
$is1="was"
}
If ($year -gt $thisyear) {
$is1="will"
$is2="be"
}

#check if the specified year is leapyear


[Boolean] $leapyear=([Boolean]! ($year%4) -and [boolean] ($year%100)) -or
[boolean]! ($year%400)

#display the result


If($leapyear) {
Write-host"$year$is1$is2 a leap year"
}
else {
Write-host"$year$is1NOT$is2 a leap year"
}

FOR LOOP
For($a=1; $a -le 10; $a++)
{
Write-host $a
}

CONDITIONAL STATEMENT
If($a -ge 0)
{
Write-host"POSITIVE NUMBER"
}
else {
Write-host"NEGATIVE NUMBER"
}

COLORED TEXT
Write-host "Text" -foregroundcolor "blue" -backgroundcolor "lime"
SOLICIT INPUT
$a=Read-host "Please enter your name"

MULTI COMMAND LINE


$a=1,2,3,4,5; $b=$a[2] Write-host $b

You might also like