PowerShell: Header Metainfo
May 11, 2020 19:57
David Jones MVP
coding
powershell
11 May 2020 19:57:13
David Jones MVP
coding powershell
coding powershell
Decided to add metainformaton to each PS file as a header comment. Needed to recusively add a template to PS files.
Prepending the template to all PS files in this directory and below
$prependFile = ""
$prepend = get-contents $prependFile
Get-ChildItem -Recurse -file -Filter "*.ps1" | foreach {$prepend + (Get-Content $_.FullName -raw) | Out-File $_.FullName}
The script to prepend the template to each PS file recursively.
The template is in the file pointed to by $prependFile.
Note that you might want to back up the folder first as it overwrites the folder.
The PS File Template
Discussion Links
The suggested template:
<#
.SYNOPSIS A summary of how the script works and how to use it.
.DESCRIPTION A long description of how the script works and how to use it.
.NOTES Information about the environment, things to need to be consider and other information.
.COMPONENT Information about PowerShell Modules to be required.
.LINK Useful Link to ressources or others.
.Parameter ParameterName Description for a parameter in param definition section. One entry thus for each parmeter.
#>
Note that <# .. #> comments in PS scripts requires PS 3 or later.
Other info apart from the header
Ref: About Requires in MS Docs
These are placed as comments outside of the header. eg.
Requires -Version 5.0
This means the script requires version 5.0 of PS, or later.
You can add a number of other requirements. See the link above.
Would be nice to automatically extract the Parameter information from the file and add a .Parameter entry for each.
Topic | Subtopic | |
Next: > | Azure Sphere Projects | BME280 Sensor (Part 3) IoT Central |
This Category Links | ||
Category: | Coding Index: | Coding |
Next: > | PowerShell | Porting from a System.Windows.Forms Form |
< Prev: | PowerShell | show-image A PS Function to Display an Image in a Windows Form |