New-Greeting.ps1
19 Sep 2025Description
Purpose
Retrieves a random message for a specified day.
Detailed Description
The GetMessageForDay method selects a random message from the predefined list of messages for the given day. It validates the input day and returns a PSCustomObject containing the date, day, time, and message.
Usage
Example 1
$greetings = [Greetings]::new()
$greetings.GetMessageForDay(“Monday”) Retrieves a random message for Monday.
Notes
Author: Luke Leigh Date: [Today’s Date]
Script
function New-Greeting {
<#
.SYNOPSIS
Creates a greeting message for a specified day.
.DESCRIPTION
The New-Greeting function generates a greeting message for a specified day of the week using the `Greetings` class. If no day is specified, it defaults to the current day. The greeting message is returned as a `PSCustomObject` containing the date, day, time, and message.
.PARAMETER Day
The day of the week for which the greeting message should be created. If not specified, the current day is used. The valid values for this parameter are defined by the `GreetingsValidator` class.
.EXAMPLE
# Example 1: Get a greeting message for Monday
PS C:\> New-Greeting -Day Monday
Date Day Time Message
---- --- ---- -------
30/06/2024 Monday 14:00 Booting up for the week, please wait...
.EXAMPLE
# Example 2: Get a greeting message for the current day
PS C:\> New-Greeting
Date Day Time Message
---- --- ---- -------
30/06/2024 Sunday 14:00 Backing up for the week ahead.
.NOTES
Author: Your Name
Date: Today's Date
#>
[CmdletBinding(DefaultParameterSetName = 'Default')]
[OutputType([string])]
Param
(
[Parameter(ParameterSetName = 'Default',
Mandatory = $false,
ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true,
HelpMessage = 'Enter the day for which the greeting message should be created.'
)]
[ValidateSet([GreetingsValidator])]
[string]$Day
)
Begin {
# Create a new instance of the Greetings class
$greetings = [Greetings]::new()
# If no day is specified, use the current day
if ([String]::IsNullOrWhiteSpace($Day)) {
$Day = $greetings.CurrentDay
}
}
Process {
# Get the greeting message for the specified day
Write-Output $($greetings.GetMessageForDay($Day))
}
}
Download
Please feel free to copy parts of the script or if you would like to download the entire script, simply click the download button. You can download the complete repository in a zip file by clicking the Download link in the menu bar on the left hand side of the page.
Report Issues
You can report an issue or contribute to this site on GitHub. Simply click the button below and add any relevant notes. I will attempt to respond to all issues as soon as possible.