Repository navigation
Description
Type of issue
Missing information
Feedback
Unlike what the linked article currently shows, the syntax diagram for Resolve-Path is the following as of v7.4.0:
Resolve-Path [-Path] <string[]> [-Relative] [-RelativeBasePath <string>] [-Credential <pscredential>] [<CommonParameters>]
Resolve-Path -LiteralPath <string[]> [-Relative] [-RelativeBasePath <string>] [-Credential <pscredential>] [<CommonParameters>]
That is, -RelativeBasePath can (now) be used with or without -Relative.
Example 7 contains the following command:
Resolve-Path -Path $ExecutablePath -RelativeBasePath $env:TEMPHowever, -RelativeBasePath has no effect there, and using an absolute input path only ever makes sense with -Relative.
The distinct uses of -RelativeBasePath with -Relative vs. without it aren't obvious; here's an attempt at a summary:
-
With
-Relative:- Returns relative paths, as strings, which describes how to get from the input paths to the reference path (which defaults to the current location), using
.and..components as needed. - This is equally useful for both relative and absolute input paths, but it is important to note that a relative input path is interpreted as relative to
-RelativeBasePath. - Examples (using literal paths, but wildcards are supported, via
-Path):
- Returns relative paths, as strings, which describes how to get from the input paths to the reference path (which defaults to the current location), using
# ABSOLUTE input path:
# Get the relative path from C:\Windows to, say, C:\Users\jdoe -> '..\Users\jdoe'
Resolve-Path $HOME -Relative -RelativeBasePath C:\Windows
# RELATIVE input path:
# Get the relative path from C:\Windows to C:\Windows\System32 -> '.\System32'
Resolve-Path System32 -Relative -RelativeBasePath C:\Windows
# This is basically the equivalent of:
# '.\' + (Get-Item (Join-Path C:\Windows System32)).Name-
Without
-Relative:-
Returns absolute paths, as
[System.Management.Automation.PathInfo]instances. -
This parameter combination It is therefore only useful with relative input paths, given that there'd be nothing to resolve for absolute ones.
-
Example:
-
# Get the absolute paths of items named Prog* in C:\
# -> [System.Management.Automation.PathInfo] instances for the following full paths:
# 'C:\Program Files'
# 'C:\Program Files (x86)'
Resolve-Path Prog* -RelativeBasePath C:\
# This is the equivalent of:
# Resolve-Path (Join-Path C:\ Prog*)Page URL
Content source URL
Author
Document Id
5cd1c325-40ec-71ee-f4b4-0091000d930b
Activity