Skip to content

New-PowershellScript

Creates a PowerShell script

param([string]$path = "bot.ps1")

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

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

	"? New '$path' created (from data/templates/New.ps1)."
	exit 0 # success
} catch {
	"?? ERROR: $($Error[0]) (script line $($_.InvocationInfo.ScriptLineNumber))"
	exit 1
}

Specifies the path and new filename ("bot.ps1" by default)

An interactive directory of PowerShell scripts.