MyPowerShellTemplates.psm1

#requires -version 5
<#
.SYNOPSIS
    <Overview of script>
.DESCRIPTION
    <Brief description of script>
.INPUTS
    <Inputs if any, otherwise state None>
.OUTPUTS
    Logs output by default to $env:temp, the users temp folder
    <Outputs if any, otherwise state None>
    <example: Log file stored in C:\Windows\Temp\<name>.log>
.NOTES
    Version: 1.0
    Author: <Name>
    Creation Date: <Date>
    Purpose/Change: Initial script development
.EXAMPLE
    <Example goes here. Repeat this attribute for more than one example>
.LINK
    Any Links with addtional information on the use of the script
#>

#region Initialisations
Set-StrictMode -Version Latest
#endregion Initialisations
#region Modules
## Import-Module ActiveDirectory
#endregion Modules
#region Declarations
[version]$Script:PstModuleVersion = "0.0.0.4"
$Script:ModuleRootFilePath = $MyInvocation.MyCommand.Path
$Script:ModuleRootFileName = $MyInvocation.MyCommand.Name
$Script:ModulePSScriptRoot = $PSScriptRoot
$Script:PublicPath = Join-Path -Path $Script:ModulePSScriptRoot -ChildPath Public
$Script:PrivatePath = Join-Path -Path $Script:ModulePSScriptRoot -ChildPath Private
# Global automation mode variable - when $true, bypasses all interactive prompts
if (-not (Get-Variable -Name PstAutomationMode -Scope Global -ErrorAction SilentlyContinue)) {
    $Global:PstAutomationMode = $false
}
# Helper function to check if we're in automation mode
function script:Test-AutomationMode {
    return ($Global:PstAutomationMode -eq $true) -or
    ($env:CI -eq 'true') -or
    ($env:GITHUB_ACTIONS -eq 'true') -or
    ($Host.Name -eq 'ServerRemoteHost') -or
    (-not [Environment]::UserInteractive)
}
#endregion Declarations
#region Execution
try {
    Write-Debug -Message "'$($Script:ModuleRootFileName)' module import starting at '$(Get-Date)', version ''"
    Write-Verbose -Message "get Public Functions in '$($Script:PublicPath)' and Export them if ps1 files exist "
    if (Test-Path "$($Script:PublicPath)\*.ps1") {
        Write-Information "'$($Script:PublicPath)' contains .ps1 files, dot sourcing files"
        Get-ChildItem -Path "$($Script:PublicPath)\*.ps1" | ForEach-Object {
            Write-Verbose "dot sourcing '$($_.FullName )'"
            . $_.FullName
        }
        Export-ModuleMember -Function (Get-ChildItem -Path "$($Script:PublicPath)\*.ps1").BaseName
    } else {
        Write-Warning "'$($Script:PublicPath)' does not contain any .ps1 files."
    }
    Write-Verbose -Message "get Private Functions in '$($Script:PrivatePath)' and Export them if ps1 files exist "
    if (Test-Path "$($Script:PrivatePath)\*.ps1") {
        Write-Information "'$($Script:PrivatePath)' contains .ps1 files, dot sourcing files"
        Get-ChildItem -Path "$($Script:PrivatePath)\*.ps1" | ForEach-Object { . $_.FullName }
    } else {
        Write-Warning "'$($Script:PrivatePath)' does not contain any .ps1 files."
    }
    # get Resources and create FileHashTables varuables
    $Resources = Get-ChildItem -Path (Join-Path -Path $PSScriptRoot -ChildPath Resources) -Directory
    foreach ($Resource in $Resources) {
        Set-Variable -Name $Resource.Name -Value $(Get-FileHashtable -Path $Resource.FullName)
    }
    Write-Output "'$($Script:ModuleRootFileName)' imported successfuly at '$(Get-Date)'"
} catch {
    if ($_.Exception -and $_.Exception.Message) {
        Write-Error "An error occurred: $($_.Exception.Message)"
    } else {
        Write-Error "An error occurred, but no additional information is available."
    }
} finally {
    Write-Debug -Message "Finally $($Script:ModuleRootFileName) at '$(Get-Date)'"
}
#endregion Execution