Search notes:

PowerShell cmdLet Resolve-Path

If invoked without the -relative option, resolve-path returns one or more System.Management.Automation.PathInfo objects with the wildcard characters expanded.
Return a list of all files with 4 characters in the filename (without extension) and the extension .txt:
resolve-path ????.txt
Return a list of all .tmp files that start with a:
resolve-path a*.tmp
Return the home directory
resolve-path ~

-relative

With the option -relative specified, resolve-path returns a list of relative paths (relative to the current directory, that is):
resolve-path ../../*.txt -relative
The returned data type is not a PathInfo object anymore, but a string.

Combining -relative with get-childItem

The following simple pipeline combines get-childItem and resolve-path -relative to return a list of all relative path names of .sql files beneath the current directory:
get-childItem -recurse -filter *.sql | select-object { resolve-path $_.fullName -relative }

Get relative path between an arbitrary directory and file/directory

The function resolve-relativePath (of the PowerShell module filesystem) allows to get a relative path from an arbitrary directory to a file or directory.

Files must exist

resolve-path requires real (existing) files to operate. It's not possible (as far as I can see) to use resolve-path -relative to find a relative path to a hypothetical file that does not yet exist, for example, in order to create its directory:
PS C:\> resolve-path $home\foo\bar\baz.txt
resolve-path : Cannot find path 'C:\Users\Rene\foo\bar\baz.txt' because it does not exist.
It is possible to circumvent this restriction in PowerShell by using the methods that are exposed via $ExecutionContext.SessionState.Path.
The DevHawk Blog alternatively suggests to set the -errorAction parameter to silentlyContinue and, in case the file does not exist, use an error variable to get the path for the inexisting file:
function resolve-always($path) {

   $resolved = resolve-path $path -errorAction silentlyContinue -errorVariable err

   if (! $resolved) {
      return $err[0].targetObject
   }

   return $resolved
}
Github repository about-PowerShell, path: /cmdlets/path/resolve/force.ps1

See also

The command parameter -credential.
Powershell command noun: path

Index