Get-MonthOfYear.ps1
19 Sep 2025Description
Purpose
Returns the current month of the year, a random month, or a shuffled list of all months.
Detailed Description
This function generates the current month of the year by default. If the -Random
switch is provided, it returns a single random month. If the -ShuffleList
switch is provided, it returns a shuffled list of all months.
Usage
Example 1
Get-MonthOfYear
Returns the current month of the year, e.g., “April”.
Example 2
Get-MonthOfYear -Random
Returns a single random month of the year, e.g., “March”.
Example 3
Get-MonthOfYear -ShuffleList
Returns a shuffled list of all months of the year, e.g., “October”, “January”, “May”, etc.
Notes
Author: Luke Leigh Date: April 3, 2025 Version: 1.1 This function uses the Get-Random
cmdlet with the -Shuffle
parameter for shuffling.
Script
<#
.SYNOPSIS
Returns the current month of the year, a random month, or a shuffled list of all months.
.DESCRIPTION
This function generates the current month of the year by default. If the `-Random` switch is provided,
it returns a single random month. If the `-ShuffleList` switch is provided, it returns a shuffled list
of all months.
.PARAMETER ShuffleList
If specified, the function returns a shuffled list of all months of the year.
.PARAMETER Random
If specified, the function returns a single random month of the year.
.EXAMPLE
Get-MonthOfYear
Returns the current month of the year, e.g., "April".
.EXAMPLE
Get-MonthOfYear -Random
Returns a single random month of the year, e.g., "March".
.EXAMPLE
Get-MonthOfYear -ShuffleList
Returns a shuffled list of all months of the year, e.g., "October", "January", "May", etc.
.NOTES
Author: Luke Leigh
Date: April 3, 2025
Version: 1.1
This function uses the `Get-Random` cmdlet with the `-Shuffle` parameter for shuffling.
#>
function Get-MonthOfYear {
[CmdletBinding()]
param (
[switch]$ShuffleList,
[switch]$Random
)
# Define the months of the year
$monthsOfYear = @(
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
)
if ($ShuffleList) {
# Use the -Shuffle parameter to shuffle the list
return $monthsOfYear | Get-Random -Shuffle
}
elseif ($Random) {
# Return a single random month
return Get-Random -InputObject $monthsOfYear
}
else {
# Return the current month
return (Get-Date).ToString("MMMM")
}
}
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.