POWERSHELL:
Create a hash table with the following fields containing appropriate values: (1)
Using the hash table you created in the previous question, write an if statement that tests whether or not the product in question has expired or not. Use the current date and time as the reference point. (2)
Change the date in the hash table to a different (probably future) date and run your if statement second time to get a different result.
1) Solution
Checking whether the product has expired or not by comparing today's date with product's expiry date which is also today's date only.
$hash = @{ product_name = "biscuit"; price = 50; expiry_date =
Get-Date }
$date = Get-Date
if($hash["expiry_date"] -gt $date)
{
write-host("The product has not expired")
}
else
{
write-host("The product has expired")
}
2) Solution second
Changing the expiry date to some future date and comparing with today's date
$hash = @{ product_name = "biscuit"; price = 50; expiry_date =
Get-Date "2020-11-30"}
$date = Get-Date
if($hash["expiry_date"] -gt $date)
{
write-host("The product has not expired")
}
else
{
write-host("The product has expired")
}
Get Answers For Free
Most questions answered within 1 hours.