Test-ScriptFileInfo

驗證腳本的批註區塊。

Syntax

Test-ScriptFileInfo
    [-Path] <String>
    [<CommonParameters>]
Test-ScriptFileInfo
    -LiteralPath <String>
    [<CommonParameters>]

Description

Cmdlet Test-ScriptFileInfo 會驗證腳本開頭的批註區塊,該腳本會與 Publish-Script Cmdlet 一起發佈。 如果批註區塊發生錯誤,此 Cmdlet 會傳回錯誤所在位置的相關資訊,或如何修正錯誤。

這是Microsoft.PowerShell.PSResourceGet中 Cmdlet 的 Proxy Cmdlet Test-PSScriptFileInfo 。 如需詳細資訊,請參閱 Test-PSScriptFileInfo

範例

範例 1:測試腳本檔案

Test-ScriptFileInfo -Path "C:\temp\temp_scripts\New-ScriptFile.ps1"

此命令會測試New-ScriptFile.ps1腳本檔案,並顯示結果。 腳本檔案包含有效的中繼資料。

範例 2:測試具有所有中繼資料屬性值的腳本檔案

Test-ScriptFileInfo -Path "D:\code\Test-Runbook.ps1" | Format-List *

Name                       : Test-Runbook
Path                       : D:\code\Test-Runbook.ps1
ScriptBase                 : D:\code
ReleaseNotes               : {contoso script now supports following features, Feature 1, Feature 2, Feature 3...}
Version                    : 1.0
Guid                       : eb246b19-17da-4392-8c89-7c280f69ad0e
Author                     : pattif
CompanyName                : Microsoft Corporation
Copyright                  : 2015 Microsoft Corporation. All rights reserved.
Tags                       : {Tag1, Tag2, Tag3}
LicenseUri                 : https://contoso.com/License
ProjectUri                 : https://contoso.com/
IconUri                    : https://contoso.com/MyScriptIcon
ExternalModuleDependencies : ExternalModule1
RequiredScripts            : {Start-WFContosoServer, Stop-ContosoServerScript}
ExternalScriptDependencies : Stop-ContosoServerScript
Description                : Contoso Script example
RequiredModules            : {RequiredModule1, @{ ModuleName = 'RequiredModule2'; ModuleVersion = '1.0' }, @{ ModuleName = 'RequiredModule3'; RequiredVersion = '2.0' }, ExternalModule1}
ExportedCommands           : {Test-WebUri, ValidateAndAdd-PSScriptInfoEntry, Get-PSScriptInfo, My-Workflow...}
ExportedFunctions          : {Test-WebUri, ValidateAndAdd-PSScriptInfoEntry, Get-PSScriptInfo, My-AdvPSCmdlet}
ExportedWorkflows          : My-Workflow

此命令會測試腳本檔案Test-Runbook.ps1,並使用管線運算子將結果傳遞至 Format-List Cmdlet 來格式化結果。

範例 3:測試沒有中繼資料的腳本檔案

Test-ScriptFileInfo -Path "D:\code\Hello-World.ps1"

Test-ScriptFileInfo : Script 'D:\code\Hello-World.ps1' is missing required metadata properties. Verify that the script file has Version, Description
and Author properties. You can use the Update-ScriptFileInfo or New-ScriptFileInfo cmdlet to add or update the PSScriptInfo to the script file.
At line:1 char:1
+ Test-ScriptFileInfo D:\code\Hello-World.ps1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidArgument: (D:\code\Hello-World.ps1:String) [Test-ScriptFileInfo], ArgumentException

+ FullyQualifiedErrorId : MissingRequiredPSScriptInfoProperties,Test-ScriptFile

此命令會測試腳本檔案Hello-World.ps1,該檔案沒有與其相關聯的中繼資料。

參數

-LiteralPath

指定一個或多個位置的路徑。 不同于 Path 參數, LiteralPath 參數的值會與輸入時完全相同。 沒有字元會被視為萬用字元。 如果路徑包含逸出字元,請用單引號括住它們。 單引號會指示 PowerShell 不要將任何字元解譯為逸出序列。

參數會對應至 的 Test-PSScriptFileInfoPath參數。

Type:String
Aliases:PSPath
Position:Named
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-Path

指定一個或多個位置的路徑。 允許使用萬用字元。 預設位置是目前目錄 (.) 。

Type:String
Position:0
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:True

輸入

String

輸出

Object