[PS] psdrive inconsistency

Discussion in 'Scripting' started by dreeschkind, May 18, 2006.

  1. dreeschkind

    dreeschkind Guest

    I can do

    PoSh 1 E:\>C:testfile.txt
    or
    PoSh 2 E:\>C:\testfile.txt

    but I can not do

    PoSh 3 E:\>env:path
    'env:path' is not recognized as a cmdlet, function, operable program, or
    script file.
    At line:1 char:8
    + env:path <<<<
    PoSh 4 E:\>env:\path
    'env:\path' is not recognized as a cmdlet, function, operable program, or
    script file.
    At line:1 char:9
    + env:\path <<<<

    The same limitation goes for variable, alias and function.
    It would feel natural for me to get the content/value of the powershell
    variable or environment variable returned.
    Calling items on the filesystem invokes them, and invoking variables usually
    prints them in powershell.
    I think invoking functions that way has already been suggested here.

    Have a look at the error message. Why does PowerShell tell me that it
    doesn't recognize the function that _exist_ at this location?

    PoSh 5 E:\>function:\help
    'function:\help' is not recognized as a cmdlet, function, operable program,
    or script file.
    At line:1 char:14
    + function:\help <<<<
     
    dreeschkind, May 18, 2006
    #1
    1. Advertisements

  2. dreeschkind

    Alan S. B. Guest

    at the PS command you have to use:
    PoSh 3 E:\>$env:path

    I.E., preceding the string with '$'. This is not necessary if used as a
    parameter. This is a different type of provider than directory paths, or some
    such. The description is in the full documentation for the latest version.
     
    Alan S. B., May 18, 2006
    #2
    1. Advertisements

  3. dreeschkind

    dreeschkind Guest

    So I can't use it without '$' at the commandline, but I can use it without
    '$' as a parameter? This seems odd.

    PoSh 4 E:\>env:\path
    'env:\path' is not recognized as a cmdlet, function, operable program, or
    script file.
    At line:1 char:9
    + env:\path <<<<

    If I can use the path of a filesystem item or a 'flat provider' item like
    "env:\path" as a parameter, then why can't I do this with any provider?

    # works
    PoSh 1 C:\>get-content env:\path
    E:\Programme;...

    # doesn't work
    PoSh 2 C:\>invoke-item function:\help
    Invoke-Item : Provider execution stopped because the provider does not
    support this operation.
    At line:1 char:12
    + invoke-item <<<< function:\help
     
    dreeschkind, May 18, 2006
    #3
  4. The generic way to get content from any provider is this:

    ${Drive:path} (ie:
    http://www.leeholmes.com/blog/AccessingEnvironmentVariablesInPowerShell.aspx)

    That accomplishes what you want.

    As for the inconsistency, the c:\test.ps1 syntax actually invokes the action
    associated with the path. An inconsistency (as you point out) is that we
    allow you to invoke untouched filesystem paths, yet we don't let you invoke
    any other provider paths. Although the environment and variable providers
    don't allow you to invoke their items (as in "invoke-item env:path"), other
    providers may.

    That is a good point -- please file it as a feature suggestion on MS
    Connect.
     
    Lee Holmes [MSFT], May 19, 2006
    #4
  5. dreeschkind

    dreeschkind Guest

    Feature request submitted here:
    https://connect.microsoft.com/feedback/ViewFeedback.aspx?SiteID=99&FeedbackID=77319
     
    dreeschkind, May 19, 2006
    #5
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.