Del via


Convert-UrnToPath

Converts a SQL Server Management Object URN to a Windows PowerShell provider path.

Syntax

Convert-UrnToPath
       [-Urn] <String>
       [-ProgressAction <ActionPreference>]
       [<CommonParameters>]

Description

The Convert-UrnToPath cmdlet converts a SQL Server Management Object Uniform Resource Name (URN) to a SQL Server provider path.

SQL Server Management Objects have a Urn property that returns a string indicating their location in the SQL Server object hierarchy.

If nodes in the Urn are SQL Server delimited identifiers with extended characters that are not supported in Windows PowerShell path nodes, the extended characters are encoded with their hexadecimal representation.

For example, a table name "Main:Table" is encoded as "Main%3ATable".

Examples

Example 1: Get a string containing the current path

PS C:\> Set-Location "SQLSERVER:\SQL\MyComputer\MyInstance\Databases\AdventureWorks2014"
PS SQLSERVER:\SQL\MyComputer\MyInstance\Databases\AdventureWorks2014> Convert-UrnToPath -Urn (Get-Item .).Urn.ToString()

SQLSERVER:\SQL\MyComputer\MyInstance\Databases\AdventureWorks2014

This command returns a string that contains the current path. The example uses the ToString() function of the Urn property to return the Urn as a string.

Example 2: Set the path location based on a URN

PS C:\> Set-Location (Convert-UrnToPath -Urn "Server[@Name='MyComputer']/Database[@Name='AdventureWorks']/Table[@Name='Address' and @Schema = 'Person']")

This command sets the path to the location specified in a SQL Server Management Object URN.

Example 3: Get database paths

PS C:\> Set-Location "SQLSERVER:\SQL\MyComputer\DEFAULT\Databases"
PS SQLSERVER:\SQL\MyComputer\DEFAULT\Databases> foreach ($Item in Get-ChildItem) { $Item.Urn.ToString() | Convert-UrnToPath }

SQLSERVER:\SQL\MyComputer\DEFAULT\Databases\AdventureWorks2014

This command returns an array of strings that contain the path to a database in the default instance. The pipeline operator is used to pass the current node URN to Convert-UrnToPath.

Parameters

-ProgressAction

Determines how PowerShell responds to progress updates generated by a script, cmdlet, or provider, such as the progress bars generated by the Write-Progress cmdlet. The Write-Progress cmdlet creates progress bars that show a command's status.

Type:ActionPreference
Aliases:proga
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Urn

Specifies a SQL Server URN that identifies the location of an object in the SQL Server hierarchy.

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

Inputs

String

Specifies a string that represents a SQL Server Management Object URN.

Outputs

String

Specifies a string that represents a SQL Server PowerShell provider path.