2024-10-01 15:11:03 +02:00
|
|
|
|
<#
|
2021-08-30 12:21:01 +02:00
|
|
|
|
.SYNOPSIS
|
2023-12-05 09:29:58 +01:00
|
|
|
|
Creates a new PowerShell script
|
2021-08-30 12:21:01 +02:00
|
|
|
|
.DESCRIPTION
|
2023-12-05 09:29:58 +01:00
|
|
|
|
This PowerShell script creates a new PowerShell script file by using the template file ../data/template.ps1.
|
2021-10-16 16:50:10 +02:00
|
|
|
|
.PARAMETER filename
|
2023-12-05 09:29:58 +01:00
|
|
|
|
Specifies the path and filename to the new script
|
2021-08-30 12:21:01 +02:00
|
|
|
|
.EXAMPLE
|
2021-09-24 17:19:49 +02:00
|
|
|
|
PS> ./new-script myscript.ps1
|
2024-10-01 13:37:53 +02:00
|
|
|
|
✅ Created the new 'myscript.ps1' PowerShell script in 1 sec
|
2021-08-30 12:21:01 +02:00
|
|
|
|
.LINK
|
|
|
|
|
https://github.com/fleschutz/PowerShell
|
2022-01-29 12:47:46 +01:00
|
|
|
|
.NOTES
|
2022-09-06 21:42:04 +02:00
|
|
|
|
Author: Markus Fleschutz | License: CC0
|
2021-08-30 12:21:01 +02:00
|
|
|
|
#>
|
|
|
|
|
|
|
|
|
|
param([string]$filename = "")
|
|
|
|
|
|
|
|
|
|
try {
|
2023-08-05 10:23:20 +02:00
|
|
|
|
if ($filename -eq "" ) { $filename = Read-Host "Enter the new filename" }
|
2023-12-05 09:29:58 +01:00
|
|
|
|
$stopWatch = [system.diagnostics.stopwatch]::startNew()
|
2021-08-30 12:21:01 +02:00
|
|
|
|
|
2023-10-31 11:25:11 +01:00
|
|
|
|
Copy-Item "$PSScriptRoot/../data/template.ps1" "$filename"
|
2021-08-30 12:21:01 +02:00
|
|
|
|
|
2023-12-05 09:29:58 +01:00
|
|
|
|
[int]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
2024-10-01 13:37:53 +02:00
|
|
|
|
"✅ Created the new '$filename' PowerShell script in $elapsed sec"
|
2021-09-27 10:09:45 +02:00
|
|
|
|
exit 0 # success
|
2021-08-30 12:21:01 +02:00
|
|
|
|
} catch {
|
2022-04-13 12:06:32 +02:00
|
|
|
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
2021-08-30 12:21:01 +02:00
|
|
|
|
exit 1
|
|
|
|
|
}
|