Skip to content

Test-Uri

SYNOPSIS

Validates whether a given string is a valid URI.

SYNTAX

Test-Uri [-Uri] <String> [-AllowRelative] [-ProgressAction <ActionPreference>] [<CommonParameters>]

DESCRIPTION

The Test-Uri function checks whether a given string is a valid URI. By default, it enforces absolute URIs. If the -AllowRelative switch is specified, it allows both absolute and relative URIs.

EXAMPLES

EXAMPLE 1

Test-Uri -Uri "https://example.com"

Output:

True

Checks if https://example.com is a valid URI, returning $true.

EXAMPLE 2

Test-Uri -Uri "invalid-uri"

Output:

False

Returns $false for an invalid URI string.

EXAMPLE 3

"https://example.com", "invalid-uri" | Test-Uri

Output:

True
False

Accepts input from the pipeline and validates multiple URIs.

PARAMETERS

-Uri

Accept one or more URI strings from parameter or pipeline.

Type: String
Parameter Sets: (All)
Aliases:

Required: True
Position: 1
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False

-AllowRelative

If specified, allow valid relative URIs.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-ProgressAction

{{ Fill ProgressAction Description }}

Type: ActionPreference
Parameter Sets: (All)
Aliases: proga

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters

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

INPUTS

OUTPUTS

[System.Boolean]

NOTES

Returns $true if the input string is a valid URI, otherwise returns $false.

https://psmodule.io/Uri/Functions/Test-Uri