# encoding: ascii
# api: powershell
# title: Get-Path
# description: Get-Path converts relative paths to drive or PSProvider -qualified paths.
# version: 0.1
# type: function
# author: Joel Bennett
# license: CC0
# function: Get-Path
# x-poshcode-id: 3054
# x-archived: 2012-02-05T03:20:18
# x-published: 2012-11-19T15:05:00
#
# Like Resolve-Path, but without requiring the path to exist ;-)
# 11.19.2011: beefarino fixed an issue with missing \ in output’s drive spec.  E.g.,  output was coming c:share\file.txt instead of c:\share\file.txt
#
function Get-Path {
[CmdletBinding(DefaultParameterSetName="DriveQualified")]
Param(
   [Parameter(Position=0,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
   [Alias("PSPath")]
   [String]      
   $Path,
   [Parameter()]
   [Switch]$ResolvedPath,
   [Parameter(ParameterSetName="ProviderQualified")]
   [Switch]$ProviderQualified
   
)
   $Drive = $Provider = $null 
   $PSPath = $PSCmdlet.SessionState.Path
   
   if($ResolvedPath -and $ProviderQualified) {
      $ProviderPaths = $PSPath.GetResolvedProviderPathFromPSPath($Path, [ref]$Provider)
   } else {
      $ProviderPaths = @($PSPath.GetUnresolvedProviderPathFromPSPath($Path, [ref]$Provider, [ref]$Drive))
      if($ResolvedPath) {
         $ProviderPaths = $PSPath.GetResolvedProviderPathFromProviderPath($ProviderPaths[0], $Provider)
      }
   }
   
   foreach($p in $ProviderPaths) {
      if($ProviderQualified -or ($Drive -eq $null)) {
         if(!$PSPath.IsProviderQualified($p)) {
            $p = $Provider.Name + '::' + $p
         }
      } else {
         if($PSPath.IsProviderQualified($p)) {
            $p = $p -replace [regex]::Escape( ($Provider.Name + "::") )
         }
         $p = $p.Replace($Drive.Root, $Drive.Name + ":\")
      } 
      $p
   }
}
