Skip to main content

⚠️ IMPORTANT This module is early in it´s development phase. Many API function and features are not yet available. You are welcome to contribute on GitHub to accelerate progress further.

PSScriptInfo

This project has adopted the following policies CodeOfConduct Contributing Security

Project status

GitHub Workflow Status Codecov Platform PowerShell Gallery License docs changelog GitHub release (latest SemVer including pre-releases) GitHub release (latest SemVer including pre-releases)

About

This module lets you update and manage a PSScriptInfo block at the beginning of each script file. This can be used keep track of version specific information about the script. Examples of information to keep in the PSScriptInfo block could be version, unique guid, tags, date created, date updated, changelog, release note, copyright, links to license, project, docs etc.

The PSScriptInfo block is wrapped with the following script block tags "<#PSScriptInfo" and "PSScriptInfo#>". The content within the block is in JSON format for easy parsing and manual updating.

<#PSScriptInfo
{
"Version" : "1.0.0.0",
"GUID" : "a3002a7c-0870-4b5f-8bed-cd31f7f23432",
"DateCreated" : "2021-03-29",
"DateUpdated" : "2021-03-30",
"ProjectSite" : "https://getps.dev"
}
PSScriptInfo#>

param (
$param1,
$param2
)

Installation

To install from the PowerShell gallery using PowerShellGet run the following command:

Install-Module PSScriptInfo -Scope CurrentUser

Usage

Add a new PSScriptInfo

To add a new PSScriptInfo block to a file that does not already have a PSScriptInfo block use the Add-PSScriptInfo cmdlet. The cmdlet takes two parameters, filepath that defines the file that you want to add a PSScriptInfo block to and Properties. Properties should be a hashtable where each key will be a root item in the PSScriptInfo block.

Add-PSScriptInfo -FilePath C:\Script\File.ps1 -Properties @{
Version = "1.0.0.0"
DateCreated = "2021-03-30"
}

Add-PSScriptInfo will throw if there is a existing PSScriptInfo in the file specified. Either specify -force to overwrite the existing PSScriptInfo block or use Update-PSScriptInfo to modify an existing PSScriptInfo block.

Get a PSScriptInfo block

To read the PSScriptInfo block from a file use the Get-PSScriptInfo cmdlet. This will read the PSScriptInfo block and return a PSCustomObject with all configured properties.

Get-PSScriptInfo -FilePath C:\Script\File.ps1

Version : 1.0.0.0
DateCreated : 2021-03-30

Remove a PSScriptInfo block

To remove a PSScriptBlock completly use the Remove-PSScriptInfo cmdlet. This cmdlet will remove the whole PSScriptInfo block. (Use Update-PSScriptInfo to remove individual properties from a PSScriptInfo)

Remove-PSScriptInfo -FilePath C:\Script\File.ps1

Update a PSScriptInfo block

To update a PSScriptInfo block within a file use the Update-PSScriptInfo cmdlet. The cmdlet has two parameters, filepath and properties. The properties parameter expects a hashtable. Keys that does is not present in the existing PSScriptInfo will be added, keys that already exist will be updated with the specified value except if the value is set to $null, then the property will be removed.

Assuming the file C:\Script\file.ps1 has the following content

<#PSScriptInfo
{
"Version" : "1.0.0.0",
"GUID" : "a3002a7c-0870-4b5f-8bed-cd31f7f23432",
"DateCreated" : "2021-03-29",
"DateUpdated" : "2021-03-30",
"ProjectSite" : "https://getps.dev"
}
PSScriptInfo#>

function foo {

}

The following example will remove the key guid

Update-PSScriptInfo -FilePath C:\Script\file.ps1 -Properties @{
guid = $null
}

To add a new key simple add the key in the hashtable

Update-PSScriptInfo -FilePath C:\Script\file.ps1 -Properties @{
LicenseURL = 'https://getps.dev'
}

To update an existing value, specify the key with the same name and the new value

Update-PSScriptInfo -FilePath C:\Script\file.ps1 -Properties @{
Version = '1.0.0.1'
DateUpdated = (get-date)
}