Add new-script.ps1

This commit is contained in:
Markus Fleschutz
2021-08-30 12:21:01 +02:00
parent 3308c4577f
commit ec9253f38a
4 changed files with 28 additions and 2 deletions

26
Scripts/new-script.ps1 Executable file
View File

@ -0,0 +1,26 @@
<#
.SYNOPSIS
new-script.ps1 [<filename>]
.DESCRIPTION
Creates a new PowerShell script.
.EXAMPLE
PS> .\new-script.ps1 myscript.ps1
.NOTES
Author: Markus Fleschutz · License: CC0
.LINK
https://github.com/fleschutz/PowerShell
#>
param([string]$filename = "")
try {
if ($filename -eq "" ) { $shortcut = read-host "Enter the new filename" }
copy-item "$PSScriptRoot/../data/template.ps1" "$filename"
"✔️ created new PowerShell script $filename"
exit 0
} catch {
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -1,32 +0,0 @@
#requires -version 4
<#
.SYNOPSIS
← enter overview of script here
.DESCRIPTION
← enter brief description of script here
.INPUTS
← enter inputs here (if any, otherwise state None)
.OUTPUTS
← enter outputs here (if any, otherwise state None)
.EXAMPLE
PS> .\template.ps1 ← enter example here (repeat this attribute for more than one example)
.NOTES
Author: ← enter full name here
License: ← enter license here
.LINK
← enter URL here
#>
param() # ← enter script parameters here
# ← enter functions here
try {
# ← enter instructions here
"✔️ Done."
exit 0
} catch {
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}