Test-PSScriptFileInfo

Tests the comment-based metadata in a .ps1 file to ensure it's valid for publication.

语法

Default (默认值)

Test-PSScriptFileInfo
    [-Path] <String>
    [<CommonParameters>]

说明

This cmdlet tests the comment-based metadata in a .ps1 file to ensure it's valid for publication to a repository.

示例

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

#>

参数

-Path

The path to .ps1 script file.

参数属性

类型:String
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:0
必需:True
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

输入

None

输出

Boolean

备注

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.