Files
PowerShell/docs/new-markdown-file.md
Markus Fleschutz d8690419ea Updated the manuals
2025-06-22 10:38:33 +02:00

2.0 KiB

The new-markdown-file.ps1 Script

This PowerShell script creates a new Markdown file from template: ../data/templates/New.md.

Parameters

/Repos/PowerShell/scripts/new-markdown-file.ps1 [[-path] <String>] [<CommonParameters>]

-path <String>
    Specifies the path and new filename (README.md by default)
    
    Required?                    false
    Position?                    1
    Default value                README.md
    Accept pipeline input?       false
    Aliases                      
    Accept wildcard characters?  false

[<CommonParameters>]
    This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, 
    WarningVariable, OutBuffer, PipelineVariable, and OutVariable.

Example

PS> ./new-markdown-file.ps1 
 New 'README.md' created (from data/templates/New.md).

Notes

Author: Markus Fleschutz | License: CC0

https://github.com/fleschutz/PowerShell

Script Content

<#
.SYNOPSIS
	Creates a Markdown file 
.DESCRIPTION
	This PowerShell script creates a new Markdown file from template: ../data/templates/New.md.
.PARAMETER path
	Specifies the path and new filename (README.md by default)
.EXAMPLE
	PS> ./new-markdown-file.ps1 
	✅ New 'README.md' created (from data/templates/New.md).
.LINK
	https://github.com/fleschutz/PowerShell
.NOTES
	Author: Markus Fleschutz | License: CC0
#>

param([string]$path = "README.md")

try {
	if (Test-Path "$path" -pathType leaf) { throw "File '$path' is already existing" }

	$pathToTemplate = Resolve-Path "$PSScriptRoot/../data/templates/New.md" 
	Copy-Item $pathToTemplate "$path"
	if ($lastExitCode -ne 0) { throw "Can't copy template to: $path" }

	"✅ New '$path' created (from data/templates/New.md)."
	exit 0 # success
} catch {
	"⚠️ Error: $($Error[0])"
	exit 1
}

(page generated by convert-ps2md.ps1 as of 06/22/2025 10:37:39)