functions/filesystem/New-Directory.ps1
function New-Directory { <# .SYNOPSIS Creates a directory if it does not already exist. .DESCRIPTION Checks whether the specified directory path exists. If it does not, the function creates the directory and writes a verbose message. If the directory already exists, a verbose message is written indicating that. .PARAMETER Path The full path of the directory to create. .OUTPUTS None .EXAMPLE New-Directory -Path 'C:\Temp\Logs' Creates the directory 'C:\Temp\Logs' if it does not exist. .NOTES Author: Jascha Vincke #> [CmdletBinding()] param ( [Parameter(Mandatory)] [string]$Path ) if (-not (Test-Path -Path $Path)) { Write-Verbose "Creating directory: $Path" return New-Item -ItemType Directory -Path $Path -Force } else { Write-Verbose "Directory already exists: $Path" return Get-Item -Path $Path } } |