First, continue with the assumptions you had for the previous recipe.
- Open a new file and paste the following content into it.
$Guests = Import-Csv './chapter-08/05-Write-GuestSeatDetails.csv' $CurrentGuest = 0 while ($CurrentGuest -lt $Guests.Length) { $Guest = $Guests[$CurrentGuest] $RowIdentifier = [byte][char](($Guest.Seat -split '-')[0].ToUpper()) $RowNumber = ($RowIdentifier - 64).ToString() switch -Regex ($RowNumber) { '1(1|2|3)$' { $RowNumber += 'th'; break } '.?1$' { $RowNumber += 'st'; break } '.?2$' { $RowNumber += 'nd'; break } '.?3$' { $RowNumber += 'rd'; break } Default { $RowNumber += 'th'; break } } $SeatNumber = ($Guest.Seat -split "-")[1] if ($SeatNumber -gt 20) { $Side = 'right' } else { $Side = 'left' } Start-Sleep -Seconds 1 Write-Host "Welcome, $($Guest.Name)! " -NoNewline Start-Sleep -Seconds 1 Write-Host "Your seat is in the $RowNumber row, to the $Side the aisle." $CurrentGuest++ }
- Run the script; the output should be the same as that of the last recipe.
- Now, create a new PowerShell file and add the following code:
$Year = Read-Host "Enter the year (YYYY) you would like to find Mothers’ Day for" $CurrentDay = Get-Date "01 May $Year" while ($CurrentDay.DayOfWeek -ne 'Sunday') { $CurrentDay = $CurrentDay.AddDays(1) } $MothersDay = $CurrentDay.AddDays(7) Write-Output "Mothers’ Day falls on $($MothersDay.ToLongDateString())."
- Run the script. Enter any year and you should get the date for Mothers’ Day for that year.