Skip to content

Get-Uri

SYNOPSIS

Converts a string into a System.Uri, System.UriBuilder, or a normalized URI string.

SYNTAX

AsUri (Default)

Get-Uri [-Uri] <String> [-ProgressAction <ActionPreference>] [<CommonParameters>]

AsUriBuilder

Get-Uri [-Uri] <String> [-AsUriBuilder] [-ProgressAction <ActionPreference>] [<CommonParameters>]

AsString

Get-Uri [-Uri] <String> [-AsString] [-ProgressAction <ActionPreference>] [<CommonParameters>]

DESCRIPTION

The Get-Uri function processes a string and attempts to convert it into a valid URI. It supports three output formats: a System.Uri object, a System.UriBuilder object, or a normalized absolute URI string. If no scheme is present, "http://" is prefixed to ensure a valid URI. The function enforces mutual exclusivity between the output format parameters.

EXAMPLES

EXAMPLE 1

Get-Uri -Uri 'example.com'

Output:

AbsolutePath   : /
AbsoluteUri    : http://example.com/
LocalPath      : /
Authority      : example.com
HostNameType   : Dns
IsDefaultPort  : True
IsFile         : False
IsLoopback     : False
PathAndQuery   : /
Segments       : {/}
IsUnc          : False
Host           : example.com
Port           : 80
Query          :
Fragment       :
Scheme         : http
OriginalString : http://example.com
DnsSafeHost    : example.com
IdnHost        : example.com
IsAbsoluteUri  : True
UserEscaped    : False
UserInfo       :

Converts 'example.com' into a normalized absolute URI string.

EXAMPLE 2

Get-Uri -Uri 'https://example.com/path' -AsUriBuilder

Output:

Scheme   : https
UserName :
Password :
Host     : example.com
Port     : 443
Path     : /path
Query    :
Fragment :
Uri      : https://example.com/path

Returns a [System.UriBuilder] object for the specified URI.

EXAMPLE 3

'example.com/path' | Get-Uri -AsString

Output:

http://example.com/path

Returns a [string] with the full absolute URI.

PARAMETERS

-Uri

The string representation of the URI to be processed.

Type: String
Parameter Sets: (All)
Aliases:

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

-AsUriBuilder

Outputs a System.UriBuilder object.

Type: SwitchParameter
Parameter Sets: AsUriBuilder
Aliases:

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

-AsString

Outputs the URI as a normalized string.

Type: SwitchParameter
Parameter Sets: AsString
Aliases:

Required: True
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.UriBuilder

System.String

System.Uri

NOTES

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