Test-PSScriptFileInfo
Tests the comment-based metadata in a .ps1
file to ensure it's valid for publication.
Syntax
Test-PSScriptFileInfo
[-Path] <String>
[<CommonParameters>]
Description
This cmdlet tests the comment-based metadata in a .ps1
file to ensure it's valid for publication
to a repository.
Examples
Example 1: Test a valid script
This example creates a new script file then runs Test-PSScriptFile
to validate the metadata
in the script.
New-PSScriptFileInfo -Path "C:\MyScripts\test_script.ps1" -Description "this is a test script"
Test-PSScriptFileInfo -Path "C:\MyScripts\test_script.ps1"
True
Example 2: Test an invalid script (missing Author)
This example runs the Test-PSScriptFile
cmdlet against a script file. The script is missing
the required Author metadata. The cmdlet writes a warning message and returns $false
.
Get-Content
is used to view the contents of the script file.
Test-PSScriptFileInfo -Path "C:\MyScripts\invalid_test_script.ps1"
Get-Content "C:\MyScripts\invalid_test_script.ps1"
WARNING: The .ps1 script file passed in wasn't valid due to: PSScript file is missing the required
Author property
False
<#PSScriptInfo
.VERSION 1.0.0.0
.GUID 7ec4832e-a4e1-562b-8a8c-241e535ad7d7
.AUTHOR
.COMPANYNAME
.COPYRIGHT
.TAGS
.LICENSEURI
.PROJECTURI
.ICONURI
.EXTERNALMODULEDEPENDENCIES
.REQUIREDSCRIPTS
.EXTERNALSCRIPTDEPENDENCIES
.RELEASENOTES
.PRIVATEDATA
#>
<#
.DESCRIPTION
this is a test script
#>
Parameters
-Path
The path to .ps1
script file.
Type: | String |
Position: | 0 |
Default value: | None |
Required: | True |
Accept pipeline input: | False |
Accept wildcard characters: | False |
Inputs
None
Outputs
Notes
The New-PSScriptFileInfo
and Update-PSScriptFileInfo
cmdlets place the #requires
statements
for required modules between the <#PSScriptInfo
and comment-based help blocks of the help file.
The Get-PSScriptFileInfo
expects #requires
statements to be placed somewhere before the
comment-based help block. Any #requires
statements placed after the comment-based help block are
ignored by Get-PSScriptFileInfo
and Publish-PSResource
.
Related Links
PSResourceGet