Skip to content

Incorrect syntax diagrams, unhelpful -RelativeBasePath example; need for clarification of the latter's functionality #10738

Closed

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:TEMP

However, -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):
# 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

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/resolve-path?view=powershell-7.4&viewFallbackFrom=powershell-7

Content source URL

https://github.com/MicrosoftDocs/PowerShell-Docs/blob/main/reference/7.4/Microsoft.PowerShell.Management/Resolve-Path.md

Author

Sean Wheeler (@sdwheeler)

Document Id

5cd1c325-40ec-71ee-f4b4-0091000d930b

Activity

  1. added
    area-management
    and removed
    needs-triage
    on Dec 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-management

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions