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

79 lines
2.0 KiB
Markdown

The *new-powershell-script.ps1* Script
===========================
This PowerShell script creates a new PowerShell script file by using the template ../data/templates/New.ps1.
Parameters
----------
```powershell
/Repos/PowerShell/scripts/new-powershell-script.ps1 [[-path] <String>] [<CommonParameters>]
-path <String>
Specifies the path and new filename ("bot.ps1" by default)
Required? false
Position? 1
Default value bot.ps1
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
-------
```powershell
PS> ./new-powershell-script.ps1
New PowerShell script 'bot.ps1' created from template 'PowerShell.ps1'.
```
Notes
-----
Author: Markus Fleschutz | License: CC0
Related Links
-------------
https://github.com/fleschutz/PowerShell
Script Content
--------------
```powershell
<#
.SYNOPSIS
Creates a PowerShell script
.DESCRIPTION
This PowerShell script creates a new PowerShell script file by using the template ../data/templates/New.ps1.
.PARAMETER path
Specifies the path and new filename ("bot.ps1" by default)
.EXAMPLE
PS> ./new-powershell-script.ps1
✅ New PowerShell script 'bot.ps1' created from template 'PowerShell.ps1'.
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
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])"
exit 1
}
```
*(page generated by convert-ps2md.ps1 as of 06/22/2025 10:37:39)*