Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 132 additions & 0 deletions PSModuleTemplate/PSModuleTemplate.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
#
# Module manifest for module 'PSModuleTemplate'
#
# Generated by: James
#
# Generated on: 22/02/2026
#

@{

# Script module or binary module file associated with this manifest.
RootModule = 'PSModuleTemplate.psm1'

# Version number of this module.
ModuleVersion = '0.1.0'

# Supported PSEditions
# CompatiblePSEditions = @()

# ID used to uniquely identify this module
GUID = '3101ef4b-0651-47b8-ac62-adbe531f52fe'

# Author of this module
Author = 'James'

# Company or vendor of this module
CompanyName = 'Unknown'

# Copyright statement for this module
Copyright = '(c) James. All rights reserved.'

# Description of the functionality provided by this module
Description = 'PSModuleTemplate'

# Minimum version of the PowerShell engine required by this module
# PowerShellVersion = ''

# Name of the PowerShell host required by this module
# PowerShellHostName = ''

# Minimum version of the PowerShell host required by this module
# PowerShellHostVersion = ''

# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
# DotNetFrameworkVersion = ''

# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
# ClrVersion = ''

# Processor architecture (None, X86, Amd64) required by this module
# ProcessorArchitecture = ''

# Modules that must be imported into the global environment prior to importing this module
# RequiredModules = @()

# Assemblies that must be loaded prior to importing this module
# RequiredAssemblies = @()

# Script files (.ps1) that are run in the caller's environment prior to importing this module.
# ScriptsToProcess = @()

# Type files (.ps1xml) to be loaded when importing this module
# TypesToProcess = @()

# Format files (.ps1xml) to be loaded when importing this module
# FormatsToProcess = @()

# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
# NestedModules = @()

# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
FunctionsToExport = @('Get-Greeting', 'Set-SimpleMessage', 'Invoke-ClassDemo')

# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
CmdletsToExport = @()

# Variables to export from this module
VariablesToExport = @()

# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
AliasesToExport = @()

# DSC resources to export from this module
# DscResourcesToExport = @()

# List of all modules packaged with this module
# ModuleList = @()

# List of all files packaged with this module
# FileList = @()

# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
PrivateData = @{

PSData = @{

# Tags applied to this module. These help with module discovery in online galleries.
# Tags = @()

# A URL to the license for this module.
# LicenseUri = ''

# A URL to the main website for this project.
# ProjectUri = ''

# A URL to an icon representing this module.
# IconUri = ''

# ReleaseNotes of this module
# ReleaseNotes = ''

# Prerelease string of this module
# Prerelease = ''

# Flag to indicate whether the module requires explicit user acceptance for install/update/save
# RequireLicenseAcceptance = $false

# External dependent modules of this module
# ExternalModuleDependencies = @()

} # End of PSData hashtable

} # End of PrivateData hashtable

# HelpInfo URI of this module
# HelpInfoURI = ''

# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
# DefaultCommandPrefix = ''

}

79 changes: 79 additions & 0 deletions PSModuleTemplate/PSModuleTemplate.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#region Authoring

###########################################################################
# PSModuleTemplate
# Author: James D'Arcy Ryan
# GitHub: https://github.com/jdarcyryan/PSModuleTemplate
# License: https://github.com/jdarcyryan/PSModuleTemplate/blob/main/LICENSE
#
# A standardized template for creating PowerShell modules with support for
# classes (PowerShell and C#), private functions, and public functions with
# automatic discovery and export of commands and aliases.
#
# LEGAL NOTICE:
# The license referenced above applies to the PSModuleTemplate repository
# and template structure only. Any module created using this template is
# subject to its own license as specified in the module's LICENSE file,
# which supersedes the template license for that specific module.
###########################################################################

#region Authoring

#region Classes

$classesPath = "$PSScriptRoot\classes"
$classesDataFilePath = "$classesPath\classes.psd1"

if (Test-Path -Path $classesDataFilePath) {
$classes = (Import-PowerShellDataFile -Path $classesDataFilePath).classes

$classes | foreach {
$currentClassPath = "$classesPath\$_"

if (!(Test-Path -Path $currentClassPath)) {
throw "Class '$_' does not exist."
}

$extension = (Get-Item -Path $currentClassPath).Extension

switch ($extension) {
'.ps1' {
# Process standard classes
. $currentClassPath
}
'.cs' {
# Process CSharp classes
Add-Type -Path $currentClassPath
}
default {
throw "Unable to process class '$_', $extension is an unsupported file type."
}
}
}
}

#endregion Classes

#region Private

$privatePath = "$PSScriptRoot\private"

if (Test-Path -Path $privatePath) {
Get-ChildItem -Path $privatePath -Filter '*.ps1' | where PSIsContainer -eq $false | foreach {
. $_.FullName
}
}

#endregion Private

#region Public

$publicPath = "$PSScriptRoot\public"

if (Test-Path -Path $publicPath) {
Get-ChildItem -Path $publicPath -Filter '*.ps1' | where PSIsContainer -eq $false | foreach {
. $_.FullName
}
}

#endregion Public
29 changes: 29 additions & 0 deletions PSModuleTemplate/classes/SimpleCalculator.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<#
.SYNOPSIS
A simple PowerShell class for basic arithmetic operations.

.DESCRIPTION
This class provides basic arithmetic functionality including addition and subtraction.
It demonstrates PowerShell class implementation within the module template.
#>
class SimpleCalculator {
[int] $LastResult

SimpleCalculator() {
$this.LastResult = 0
}

[int] Add([int] $a, [int] $b) {
$this.LastResult = $a + $b
return $this.LastResult
}

[int] Subtract([int] $a, [int] $b) {
$this.LastResult = $a - $b
return $this.LastResult
}

[int] GetLastResult() {
return $this.LastResult
}
}
40 changes: 40 additions & 0 deletions PSModuleTemplate/classes/StringHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;

namespace PSModuleTemplate
{
/// <summary>
/// A simple C# class for string manipulation operations.
/// </summary>
public class StringHelper
{
/// <summary>
/// Reverses the characters in a string.
/// </summary>
/// <param name="input">The string to reverse.</param>
/// <returns>The reversed string.</returns>
public static string ReverseString(string input)
{
if (string.IsNullOrEmpty(input))
return input;

char[] charArray = input.ToCharArray();
Array.Reverse(charArray);
return new string(charArray);
}

/// <summary>
/// Counts the number of words in a string.
/// </summary>
/// <param name="input">The string to count words in.</param>
/// <returns>The number of words.</returns>
public static int CountWords(string input)
{
if (string.IsNullOrWhiteSpace(input))
return 0;

string[] words = input.Split(new char[] { ' ', '\t', '\n', '\r' },
StringSplitOptions.RemoveEmptyEntries);
return words.Length;
}
}
}
6 changes: 6 additions & 0 deletions PSModuleTemplate/classes/classes.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@{
classes = @(
,'SimpleCalculator.ps1'
,'StringHelper.cs'
)
}
22 changes: 22 additions & 0 deletions PSModuleTemplate/private/Get-CurrentUser.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<#
.SYNOPSIS
Gets the current user's name from the environment.

.DESCRIPTION
This private function retrieves the current user's name from the Windows environment variables.
It provides a simple way to get the logged-in user's identity.

.EXAMPLE
Get-CurrentUser

Returns the current user's name, e.g., "JohnDoe"

.NOTES
This is a private helper function used internally by the module.
#>
function Get-CurrentUser {
[CmdletBinding()]
param()

return $env:USERNAME
}
48 changes: 48 additions & 0 deletions PSModuleTemplate/private/Test-StringLength.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<#
.SYNOPSIS
Tests if a string meets the specified length requirements.

.DESCRIPTION
This private function validates whether a given string meets minimum and maximum length requirements.
It returns a boolean value indicating whether the string passes the length validation.

.PARAMETER InputString
The string to test for length requirements.

.PARAMETER MinLength
The minimum required length for the string. Default is 1.

.PARAMETER MaxLength
The maximum allowed length for the string. Default is 100.

.EXAMPLE
Test-StringLength -InputString "Hello" -MinLength 3 -MaxLength 10

Returns: $true

.EXAMPLE
Test-StringLength -InputString "Hi" -MinLength 5

Returns: $false

.NOTES
This is a private helper function for string validation within the module.
#>
function Test-StringLength {
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[AllowEmptyString()]
[string]
$InputString,

[int]
$MinLength = 1,

[int]
$MaxLength = 100
)

$length = $InputString.Length
return ($length -ge $MinLength -and $length -le $MaxLength)
}
Loading