Cmdlets

Choose a cmdlet from the list on the left or search for a specific cmdlet. Choose a cmdlet from the list or search for a specific cmdlet.
About Help  Providers
 

Test-Script

Test-Script

pscx.dll

Synopsis

PSCX Cmdlet: Determines whether a PowerShell script has any syntax errors.

Syntax

Test-Script [-Path] [-Context] [<CommonParameters>]

Test-Script [-InputObject] [-Context] [<CommonParameters>]

Test-Script [-LiteralPath] [-Context] [<CommonParameters>]

Detailed Description

Determines whether a PowerShell script has any syntax errors using the PowerShell script tokenizer.

Parameters

-LiteralPath <String[]>

Specifies a path to the item. The value of -LiteralPath is used exactly as it is typed. No characters are interpreted as wildcards. If the path includes escape characters, enclose it in single quotation marks. Single quotation marks tell Windows PowerShell not to interpret any characters as escape sequences.

Aliases

None

Required?

true

Position

1

Default value

None

Accept pipeline input?

true (ByPropertyName)

Accept wildcard characters?

false

-Path <String[]>

Specifies the path to the file to process. Wildcard syntax is allowed.

Aliases

None

Required?

true

Position

1

Default value

None

Accept pipeline input?

true (ByPropertyName)

Accept wildcard characters?

true

-InputObject <PSObject>

Accepts an object as input to the cmdlet. Enter a variable that contains the objects or type a command or expression that gets the objects.

Aliases

None

Required?

true

Position

named

Default value

None

Accept pipeline input?

true (ByValue)

Accept wildcard characters?

false

-Context <Int32[]>

The number of lines of source script to show before and after the line containing the syntax error.

Aliases

None

Required?

false

Position

named

Default value

None

Accept pipeline input?

false

Accept wildcard characters?

false

Input Type

System.String

Return Type

System.Boolean

Notes

Examples

-------------------------- EXAMPLE 1 --------------------------

Displays syntax errors and returns a boolean indicating if there were.

C:\PS> Test-Script foo.ps1

-------------------------- EXAMPLE 2 --------------------------

Returns a boolean indicating if there were any syntax errors, suppressing all warnings.

C:\PS> Test-Script foo.ps1 -WarningAction SilentlyContinue

-------------------------- EXAMPLE 3 --------------------------

Displays syntax errors as well as the line of script before and after the line containing each syntax error. Returns a boolean indicating if there was a syntax error.

C:\PS> Test-Script foo.ps1 -Context 1