MariusTestModule.psm1
|
[CmdletBinding()] param() $baseName = [System.IO.Path]::GetFileNameWithoutExtension($PSCommandPath) $script:PSModuleInfo = Import-PowerShellDataFile -Path "$PSScriptRoot\$baseName.psd1" $script:PSModuleInfo | Format-List | Out-String -Stream | ForEach-Object { Write-Debug $_ } $scriptName = $script:PSModuleInfo.Name Write-Debug "[$scriptName] - Importing module" #region [functions] - [public] Write-Debug "[$scriptName] - [functions] - [public] - Processing folder" #region [functions] - [public] - [Get-PSModuleTest] Write-Debug "[$scriptName] - [functions] - [public] - [Get-PSModuleTest] - Importing" function Get-PSModuleTest { <# .SYNOPSIS Performs tests on a module. .DESCRIPTION Performs tests on a module. .EXAMPLE ```pwsh Test-PSModule -Name 'World' ``` "Hello, World!" .LINK https://psmodule.io/MariusTestModule/Functions/Get-PSModuleTest/ #> [CmdletBinding()] param ( # Name of the person to greet. [Parameter(Mandatory)] [string] $Name ) Write-Output "Hello, $Name!" } Write-Debug "[$scriptName] - [functions] - [public] - [Get-PSModuleTest] - Done" #endregion [functions] - [public] - [Get-PSModuleTest] #region [functions] - [public] - [DateAndTime] Write-Debug "[$scriptName] - [functions] - [public] - [DateAndTime] - Processing folder" #region [functions] - [public] - [DateAndTime] - [Get-CurrentDateTime] Write-Debug "[$scriptName] - [functions] - [public] - [DateAndTime] - [Get-CurrentDateTime] - Importing" function Get-CurrentDateTime { <# .SYNOPSIS Returns the current date and time in a specified format. .DESCRIPTION Returns the current date and time formatted according to the specified format string. Supports common format presets or custom format strings. The Short and Long presets follow the current culture of the calling session, while ISO8601 is culture-invariant. .EXAMPLE Get-CurrentDateTime Returns the current date and time in the default format (yyyy-MM-dd HH:mm:ss). .EXAMPLE Get-CurrentDateTime -Format 'Short' Returns the current date in short date format. .EXAMPLE Get-CurrentDateTime -Format 'Custom' -CustomFormat 'dddd, MMMM dd, yyyy' Returns the current date in a custom format like "Monday, January 20, 2026". .LINK https://psmodule.io/MariusTestModule/Functions/DateAndTime/Get-CurrentDateTime/ #> [OutputType([string])] [CmdletBinding()] param ( # The format preset to use for the date and time output. [Parameter()] [ValidateSet('Default', 'Short', 'Long', 'ISO8601', 'Custom')] [string] $Format = 'Default', # Custom format string when Format is set to 'Custom'. [Parameter()] [string] $CustomFormat = 'yyyy-MM-dd HH:mm:ss' ) $currentDateTime = Get-Date switch ($Format) { 'Default' { $currentDateTime.ToString('yyyy-MM-dd HH:mm:ss') } 'Short' { $currentDateTime.ToShortDateString() } 'Long' { $currentDateTime.ToLongDateString() } 'ISO8601' { $currentDateTime.ToString('o') } 'Custom' { $currentDateTime.ToString($CustomFormat) } } } Write-Debug "[$scriptName] - [functions] - [public] - [DateAndTime] - [Get-CurrentDateTime] - Done" #endregion [functions] - [public] - [DateAndTime] - [Get-CurrentDateTime] Write-Debug "[$scriptName] - [functions] - [public] - [DateAndTime] - Done" #endregion [functions] - [public] - [DateAndTime] #region [functions] - [public] - [Greetings] Write-Debug "[$scriptName] - [functions] - [public] - [Greetings] - Processing folder" #region [functions] - [public] - [Greetings] - [Get-Greeting] Write-Debug "[$scriptName] - [functions] - [public] - [Greetings] - [Get-Greeting] - Importing" function Get-Greeting { <# .SYNOPSIS Returns a greeting message. .DESCRIPTION Returns a simple greeting message for the specified time of day. Optionally includes the user's name in the greeting. .EXAMPLE Get-Greeting -TimeOfDay 'Morning' Returns "Good Morning!" to the user. .EXAMPLE Get-Greeting -TimeOfDay 'Evening' Returns "Good Evening!" to the user. .EXAMPLE Get-Greeting -TimeOfDay 'Morning' -Name 'Alice' Returns "Good Morning, Alice!" to the user. .LINK https://psmodule.io/MariusTestModule/Functions/Greetings/Get-Greeting/ #> [OutputType([string])] [CmdletBinding()] param ( # The time of day for the greeting. [Parameter()] [ValidateSet('Morning', 'Afternoon', 'Evening')] [string] $TimeOfDay = 'Morning', # Optional name to include in the greeting. [Parameter()] [string] $Name ) if ($Name) { "Good $TimeOfDay, $Name!" } else { "Good $TimeOfDay!" } } Write-Debug "[$scriptName] - [functions] - [public] - [Greetings] - [Get-Greeting] - Done" #endregion [functions] - [public] - [Greetings] - [Get-Greeting] Write-Debug "[$scriptName] - [functions] - [public] - [Greetings] - Done" #endregion [functions] - [public] - [Greetings] Write-Debug "[$scriptName] - [functions] - [public] - Done" #endregion [functions] - [public] #region Member exporter $exports = @{ Alias = '*' Cmdlet = '' Function = @( 'Get-CurrentDateTime' 'Get-Greeting' 'Get-PSModuleTest' ) Variable = '' } Export-ModuleMember @exports #endregion Member exporter |