MariusTestModule.psm1
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute( 'PSAvoidAssignmentToAutomaticVariable', 'IsWindows', Justification = 'IsWindows doesnt exist in PS5.1' )] [Diagnostics.CodeAnalysis.SuppressMessageAttribute( 'PSUseDeclaredVarsMoreThanAssignments', 'IsWindows', Justification = 'IsWindows doesnt exist in PS5.1' )] [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" if ($PSEdition -eq 'Desktop') { $IsWindows = $true } #region [functions] - [public] Write-Debug "[$scriptName] - [functions] - [public] - Processing folder" #region [functions] - [public] - [Get-CurrentDateTime] Write-Debug "[$scriptName] - [functions] - [public] - [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. .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. .LINK https://MariusStorhaug.github.io/MariusTestModule/Functions/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] - [Get-CurrentDateTime] - Done" #endregion [functions] - [public] - [Get-CurrentDateTime] #region [functions] - [public] - [Get-Greeting] Write-Debug "[$scriptName] - [functions] - [public] - [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://MariusStorhaug.github.io/MariusTestModule/Functions/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] - [Get-Greeting] - Done" #endregion [functions] - [public] - [Get-Greeting] #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://MariusStorhaug.github.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] 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 |