(view source code of leapyear.ps as plain text)
## 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 yearparam( [int]$year = ( Get-Date ).Year )
# Get the current year[int]$thisyear = ( Get-Date ).Year
# Format the output text (past, present 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 a leap year[boolean]$leapyear = ( [boolean]!( $year % 4 ) -and [boolean]( $year % 100 ) ) -or [boolean]!( $year % 400 )
# Display the resultIf ( $leapyear ) {
Write-Host "$year $is1$is2 a leap year"
}Else {
Write-Host "$year $is1 NOT$is2 a leap year"
}page last modified: 2025-10-11; loaded in 0.0066 seconds