Public/New-SpecFolder.ps1

function New-specFolder {
    <#
    .SYNOPSIS
    Creates a new folder at the specified path if it does not already exist.
 
    .DESCRIPTION
    The New-SpecFolder function creates a new folder at the specified path if it does not already exist.
    If the folder already exists, it provides a message indicating that the folder is already present (using write-verbose).
 
    .PARAMETER Path
    Specifies the path where the new folder should be created. It accepts input from pipeline or direct parameter input.
 
    .EXAMPLE
    "C:\ExampleFolder", "C:\AnotherFolder" | New-SpecFolder
    Creates new folders at the paths "C:\ExampleFolder" and "C:\AnotherFolder" sent through the pipeline.
 
    .EXAMPLE
    New-SpecFolder -Path "C:\ExampleFolder", "C:\AnotherFolder"
    Creates new folders at the paths "C:\ExampleFolder" and "C:\AnotherFolder" provided via the -Path parameter.
 
    .INPUTS
    System.String[]
 
    .NOTES
    Author : owen.heaume
    Version : 2.0
    #>


    [cmdletbinding()]
    param (
        [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
        [string[]]$Path
    )

    process {
        # Process each input path
        foreach ($p in $Path) {
            #if (![System.IO.Directory]::Exists($p)) { # faster than test path - impossible to unit test!
            try {
                Write-Verbose "Creating folder '$p'"
                $null = New-Item -ItemType Directory -Path $p -ea Stop
                Write-Verbose "Folder '$p' created"
            } catch {
                Write-Error "An error occurred: $_"
            }
        }
    }
}