Convert-UrnToPath

Converts a SQL Server Management Object URN to a SQL Server PowerShell provider path.
Convert-UrnToPath -Urn* <string> [<CommonParameters>]

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 that have extended characters not supported in PowerShell path nodes, the extended characters are encoded with their hexadecimal representation. For example, a table name “My:Table” is encoded as “My%3ATable”.

Parameters
-Urn <string>

  • This value is required
  • Accepts pipeline input ByValue

A character string containing a SQL Server Unique Resource Name (URN). A SQL Server URN is a string that identifies the location of an object in the SQL Server hierarchy. URNs have the same information as a SQL Server PowerShell path, only in a different format. SQL Server Management Objects have a Urn property.

<CommonParameters>

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

Inputs

String

A character string containing a SQL Server Management Object URN.

Outputs

String

A character string containing a SQL Server PowerShell provider path.

Examples
  1. Returns a character string containing the current path:
    C:PS> Set-Location SQLSERVER:SQLMyComputerMyInstanceDatabasesAdventureWorks2008R2
    Convert-UrnToPath -Urn (Get-Item .).Urn.ToString()
    
       SQLSERVER:SQLMyComputerMyInstanceDatabasesAdventureWorks2008R2

    The example uses the ToString() function of the SMO Urn property to return the Urn as a character string.

  2. Sets the path to the location specified in a SQL Server Management Object URN:
    C:PS> Set-Location ( Convert-UrnToPath -Urn "Server[@Name='MyComputer']/Database[@Name='AdventureWorks']/Table[@Name='Address' and @Schema = 'Person']" )
    
  3. Returns a set of character strings, each containing the path to a database in the default instance:
    C:PS> Set-Location SQLSERVER:SQLMyComputerDEFAULTDatabases
    foreach ($Item in Get-ChildItem) { $Item.Urn.ToString() | Convert-UrnToPath}
    
       SQLSERVER:SQLMyComputerDEFAULTDatabasesAdventureWorks2008R2

    Uses a pipeline to pass the current node URN to Convert-UrnToPath

Additional Notes
 
Related Links

Decode-SqlName
Encode-SqlName