Validates a comment block for a script.
Test-ScriptFileInfo -LiteralPath* <String> [<CommonParameters>]
Test-ScriptFileInfo [-Path*] <String> [<CommonParameters>]

The Test-ScriptFileInfo cmdlet validates the comment block at the beginning of a script that will be published with the Publish-Script cmdlet. If the comment block has an error, this cmdlet returns information about where the error is located or how to correct it.

-LiteralPath <String>

Specifies a path to one or more locations. Unlike the Path parameter, the value of the LiteralPath parameter is used exactly as it is entered. No characters are interpreted as wildcards. If the path includes escape characters, enclose them in single quotation marks. Single quotation marks tell Windows PowerShell not to interpret any characters as escape sequences.

-Path <String>

Specifies a path to one or more locations. Wildcards are permitted. The default location is the current directory (.).


This cmdlet supports the common parameters: Verbose, Debug,ErrorAction, ErrorVariable, WarningAction, WarningVariable,OutBuffer, PipelineVariable, and OutVariable.

  1. Test a script file:
    PS C:> Test-ScriptFileInfo -Path "C:temptemp_scriptsNew-ScriptFile.ps1"
       Version    Name                      Author               Description
       -------    ----                      ------               -----------
       1.0        New-ScriptFile            pattif               my new script file test

    This command tests the New-ScriptFile.ps1 script file and displays the results. The script file includes valid metadata.

  2. Test a script file that has values for all metadata properties:
    PS C:> Test-ScriptFileInfo -Path "D:codeTest-Runbook.ps1 | Format-List * Name                       : Test-Runbook
    Path                       : D:codeTest-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                  : c 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

    This command tests the script file Test-Runbook.ps1 and uses the pipeline operator to pass the results to the Format-List cmdlet to format the results.

  3. Test a script file that has no metadata:
    PS C:> Test-ScriptFileInfo -Path "D:codeHello-World.ps1"
    Test-ScriptFileInfo : Script 'D:codeHello-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:codeHello-World.ps1
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (D:codeHello-World.ps1:String) [Test-ScriptFileInfo], ArgumentException
       + FullyQualifiedErrorId : MissingRequiredPSScriptInfoProperties,Test-ScriptFile

    This command tests the script file Hello-World.ps1, which has no metadata associated with it.

Related Links