Skip to content

Convert-Path should work with non-existent paths #2993

Open

Description

@Jaykul

It seem clear to me that a design mistake was made when Resolve-Path and Convert-Path were created, and they both return only resolved paths (i.e. the path must exist).

The right design would be to have Convert-Path not care if the path exists, and if you care, you use both commands.

Since that ship has sailed, I propose adding a -Unresolved switch to Convert-Path to change it to do what it should have done all along, called GetUnresolvedProviderPathFromPSPath instead of calling GetResolvedProviderPathFromPSPath.

If nobody has a problem with that ... I can send a PR

Activity

  1. iSazonov commented on Jan 13, 2017

    @iSazonov
    Collaborator

    Great! Make PR.
    I'd only made the switch more descriptive: -UnresolvePath?

  2. megamorf commented on Jan 21, 2017

    @megamorf
    Contributor

    I'd suggest something along the lines of -SkipPathCheck similar to the other Skip switches as mentioned in #2006

  3. iSazonov commented on Jan 21, 2017

    @iSazonov
    Collaborator

    Perhaps Keith Hill (@rkeithhill) will again offer a good option.

  4. iSazonov commented on Oct 31, 2018

    @iSazonov
    Collaborator

    Steve Lee (@SteveL-MSFT) Michael Klement (@mklement0) Can we approve the new behavior and parameter?

  5. SteveL-MSFT commented on Oct 31, 2018

    @SteveL-MSFT
    Member

    The new behavior behind a switch seems fine. cc Hemant Mahawar (@HemantMahawar) if he has any good suggestions on naming.

  6. mklement0 commented on Oct 31, 2018

    @mklement0
    Contributor

    Opting out of behavior is more typically done with -No* parameters (-NoNewline, -NoProxy, -NoClobber, ... - Get-Module and Invoke-WebRequest/RestMethod are, unfortunately, dissenters and use -Skip*)

    Therefore: -NoResolve, perhaps?

  7. HemantMahawar commented on Oct 31, 2018

    @HemantMahawar
    Contributor

    TBH, -Skip<Something> and -No<Something> are very close, although have very subtle difference.

    • -Skip<Something> used in cmdlets ((SkipCertificateCheck, SkipEditionCheck, SkipHeaderValidation, SkipNetworkProfileCheck, SkipCACheck, SkipCNCheck, SkipRevocationCheck) ) is typically for bypassing some check.

    • -No<Something> used in cmdlets ((NoClobber, NoNewline, NoServiceRestart, NoTypeInformation, NoProxy, NoRecurse, NoQualifier, NoNewWindow, NoNewScope, NoMachineProfile, NoEnumerate, NoEncryption, NoElement, NoCompression, NoWait)) is typically about not taking specific action.

    In this case -SkipPathCheck (or maybe -SkipPathResolution or -SkipPathValidation) seems more appropriate.

  8. mklement0 commented on Oct 31, 2018

    @mklement0
    Contributor

    Thanks, Hemant Mahawar (@HemantMahawar), I see the difference, but I personally don't think it's strong enough to warrant reflection in distinct parameter names.

    Case in point: You could equally argue that the requested behavior here is not taking the action of resolving the path.

    To put it differently: I think the existing -Skip* parameters should have been named -No* instead to begin with for consistency (though, should we reach a consensus, we could introduce aliases for consistency going forward).

  9. mklement0 commented on Oct 31, 2018

    @mklement0
    Contributor

    A couple more thoughts: No is shorter and less ambiguous than Skip, which:

    • has plausible synonyms such as "bypass", "omit", ...
    • is also in use with significantly different semantics (
      Import-Cli -Skip <int>, Select-Object -Skip <int> -SkipLast <int> -SkipIndex <int[]>)
  10. SteveL-MSFT commented on Oct 31, 2018

    @SteveL-MSFT
    Member

    @PowerShell/powershell-committee reviewed this and recommends -SkipValidation

  11. added
    Committee-ReviewedPS-Committee has reviewed this and made a decision
    and removed
    Review - CommitteeThe PR/Issue needs a review from the PowerShell Committee
    on Oct 31, 2018
  12. 7 remaining items

  13. added
    WG-Engine-Providersbuilt-in PowerShell providers such as FileSystem, Certificates, Registry, etc.
    on Dec 18, 2021
  14. doctordns commented on Jun 1, 2022

    @doctordns
    Collaborator

    The Powershell Cmdlet working group reviewed this and agree that adding a switch to skip the path validation is a good idea.

    But what should the switch name be? We discussed two alternatives -SkipValidation or -SkipPathValidation.

    Comments

  15. SteveL-MSFT commented on Jun 1, 2022

    @SteveL-MSFT
    Member

    If there is ever additional validation in the future, we should be more specific, so my preference is -SkipPathValidation

  16. added
    Up-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributors
    on Jun 1, 2022
  17. doctordns commented on Jun 1, 2022

    @doctordns
    Collaborator

    Having discussed this further, the parameter name should be -SkipPathValidation

  18. Jaykul commented on Jun 3, 2022

    @Jaykul
    ContributorAuthor

    I'm concerned about this -SkipPathValidation parameter name and about what Ilya (@iSazonov) wrote:

    ... GetResolvedProviderPathFromPSPath resolves glob chars vs GetUnresolvedProviderPathFromPSPath doesn't ... I believe we want GetResolvedProviderPathFromPSPath but internal one with allowNonexistingPaths=true parameter.

    I thought we were all on the same page that this would actually not resolve paths ...

    As I said before:

    we're not (just) skipping validation, we're going to not "resolve" the path to an existing folder -- which means that if we're passed a path with wildcards, we would return a path that still has wildcards in it, right?

    I mean, if you won't verify the existence of the file, then you cannot resolve the wildcards, right?

  19. danielzgtg commented on Jun 18, 2023

    @danielzgtg

    We could use a more conventional name -Force, which would make it consistent with Set-Item

  20. ArmaanMcleod commented on Dec 15, 2023

    @ArmaanMcleod
    Contributor

    I recently needed path validation to be skipped and also think it would he a great addition to Convert-Path. I'll be happy to raise a PR once I can get the code change ready.

  21. iSazonov commented on Dec 15, 2023

    @iSazonov
    Collaborator

    I don't see conclusion about what new behavior should be. Obviously "glob expansion", "validation" and "existence" are not the same things.

  22. agowa commented on Mar 26, 2024

    @agowa

    Hi, I was pointed here because of a similar design Issue, so what's now the difference between -No* and -Skip*? When would I use one over the other? Maybe it's because I'm not a native speaker, but all of the examples given back here #2993 (comment) don't really help "solve" that mystery for me. All of these sound just perfectly fine:
    NoCertificateCheck, NoEditionCheck, NoHeaderValidation, NoNetworkProfileCheck, NoCACheck, NoCNCheck, NoRevocationCheck, ... also they more clearly indicate being the antonyms to a default behavior. Is it now "best practice" to use these switches instead of using either param([switch]$CertificateCheck=$true) or param([switch]$SkipCertificateCheck=$false)?

    The only difference I see is that the -No* ones aren't auto generated for switches right now and -Skip* is often used instead of a default $true-switch that forces a specific feature to be enabled by default. Where as -No is currently used either as the antonym to another switch or boolean-filtering (basically to avoid to query data that would be dropped by an where-objects call right after, basically a "query-time where-object") but not features. Like it'd be function Get-MyAccounts{ param([switch]$NoServiceAccounts) }. Is this the "best practice" now/still?
    (Similarly -Not is often used to filter non-boolean data and lists. e.g. Get-WUInstall -NotUpdateID XXXX queries the complement to Get-WUInstall -UpdateID XXXX [and technically those two also only exist to work around not being able to optimize Get-WUInstall | Where-Object UpdateID -eq/ne XXXX at query time]).
    [Edit: With the exception of -Skip (by itself and not a suffix) also being used for an amount. But as -Skip 5 is different than -SkipNr 5 it kinda makes sense, at least until we also add -Ignore* into the mix...]

    Is there a dedicated issue or proposal for this? It is kinda misplaced within an issue about Convert-Path, I think.
    Also I'd like keep posted about this topic and I'd argue for have auto generated No switches for every defined one, that'd remove a bunch of validationscript-blocks :D

    (Also there is a 3rd one -Ignore* that similarly shares the same meaning and no clearly stated coding-convention either)

  23. mklement0 commented on May 19, 2025

    @mklement0
    Contributor

    Klaus Frank (@agowa):

    • Indeed, I agree that there's no meaningful difference between -No* and -Skip*, and, as I've previously argued, introducing -Skip* parameters was ill-advised to begin with.

    • In general, switch parameters should never default to $true, as that would contravene user expectations. Thus, opting out of default behaviors should be implemented via -No* switches.

    • As for auto-generated -No switch variants:

      • The above implies that negating switches is best done implicitly, by omitting them in invocations.

      • However, explicit negation is still situationally called for, and PowerShell provides a syntax for that: follow the switch name by : (and optional whitespace) and $false; .e.g., -NoValidation:$false

        • This is a conceptual necessity for situationally overriding switches whose default value is implied by preference variables, e.g., -Confirm:$false
        • It is also helpful when argument values are constructed programmatically, notably via splatting.
        • Sadly, the way this syntax is handled for [switch] parameters that are used to select a parameter set by making them mandatory is likely to lead to broken implementations, including for several built-in cmdlets, as of this writing:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-FileSystem-Providerspecific to the FileSystem providerCommittee-ReviewedPS-Committee has reviewed this and made a decisionIssue-Enhancementthe issue is more of a feature request than a bugKeepOpenThe bot will ignore these and not auto-closeUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdletsgeneral cmdlet issuesWG-Engine-Providersbuilt-in PowerShell providers such as FileSystem, Certificates, Registry, etc.WG-NeedsReviewNeeds a review by the labeled Working Group

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions