In: Computer Science
Write a PowerShell script that will ask your name, Date of Birth (DOB). Print a message on console with a message like the examples. a. If the DOB you entered is in the future, print “Hello XXXXX, there are XXX days to your Birthday!” b. If the DOB you entered is today, print “Hello XXXXX, happy birthday!” c. If the DOB you entered is in the past, print “Hello XXXXX, your next birthday will be in XXX days.” d. Replace the XXXXX with the user input. XXX must be calculated.
Below is the solution:
$Name = Read-Host "Please enter your name" #read name
$DOB = Read-Host "Enter date of birth" #read dob 10/20/2020
$NumberOfDays=(New-TimeSpan -End $DOB).Days #fins the days
if ($NumberOfDays -eq 0) { #check days is 0
Write-Host "Hello " $Name", happy birthday!"
#print happy birthday
}
elseif ($NumberOfDays -gt 0){ #check days is > 0
Write-Host “Hello"$Name ", there are "
$NumberOfDays " days to your Birthday!” #print days left
birthday
}
elseif ($NumberOfDays -lt 0){ #check days is < 0
Write-Host "Hello " $Name ", Your next birthday
will be in " (365-(-($NumberOfDays))) "days" #print days to
birthday
}
sample output: