Windows Vista Forums

PSDrive Function
  1. #1


    BrianJT Guest

    PSDrive Function

    I am trying to set up a function that allows me type in "Script:" <no
    quotes> and go to a PSdrive I have mapped on the local file system, just
    like typing C: or D: would. I wrote this function for my profile:



    function global:Script: { Set-Location Script: }

    I modeled after the function in profile.ps1 file in the example directory.
    Seems pretty simple, I do a dir on the Function drive and it shows up as
    Script: and looks fine, but if I type Script: I get a function does not
    exist error. However, if I run type global:Script: it works fine.

    Any help would be great,

    Brian JT


      My System SpecsSystem Spec

  2. #2


    RichS Guest

    RE: PSDrive Function

    Your problem comes down to the use of Script: I think. PowerShell has a
    number of levels of scope for variables including global, local and script.
    See

    get-help about_scope for full details

    When you just type script: Powershell's assumption is that you are dealing
    with the script scope and it can't find the function. When you type
    global:script: you are explicitly telling PowerShell to use the script:
    function in the global scope which it does know how to find.

    If you use a different name instead of script it should work. I tested your
    function as

    function global:Scripts: { Set-Location Script: }

    and it worked - with or without the use of global:

    Hope this helps
    --
    Richard Siddaway

    Please note that all scripts are supplied "as is" and with no warranty


    "BrianJT" wrote:

    > I am trying to set up a function that allows me type in "Script:" <no
    > quotes> and go to a PSdrive I have mapped on the local file system, just
    > like typing C: or D: would. I wrote this function for my profile:
    >
    > function global:Script: { Set-Location Script: }
    >
    > I modeled after the function in profile.ps1 file in the example directory.
    > Seems pretty simple, I do a dir on the Function drive and it shows up as
    > Script: and looks fine, but if I type Script: I get a function does not
    > exist error. However, if I run type global:Script: it works fine.
    >
    > Any help would be great,
    >
    > Brian JT
    >
    >


      My System SpecsSystem Spec

  3. #3


    Thomas Lee Guest

    Re: PSDrive Function

    In message <eUpnKAHPHHA.3544@TK2MSFTNGP03.phx.gbl>, BrianJT <no@no.com>
    writes
    >I am trying to set up a function that allows me type in "Script:" <no
    >quotes> and go to a PSdrive I have mapped on the local file system, just
    >like typing C: or D: would. I wrote this function for my profile:
    >
    >function global:Script: { Set-Location Script: }


    In my case, I keep my scripts in d:\foo. I use:

    PSH [D:\foo]: New-PSDrive -name script -psProvider filesystem -root
    d:\foo

    Name Provider Root
    ---- -------- ----
    script FileSystem D:\foo

    PSH [D:\foo]: dir script:

    Directory: Microsoft.PowerShell.Core\FileSystem::\foo

    Mode LastWriteTime Length Name
    ---- ------------- ------ ----
    ....



    Hope this helps.

    --
    Thomas Lee
    doctordns@gmail.com
    MVP - Admin Frameworks and Security

      My System SpecsSystem Spec

  4. #4


    Andrew Watt [MVP] Guest

    Re: PSDrive Function

    Brian,

    I think that PowerShell is treating "script" in some respects as if it
    was a reserved word.

    Andrew Watt MVP

    On Sat, 20 Jan 2007 00:50:22 -0800, "BrianJT" <no@no.com> wrote:

    >I am trying to set up a function that allows me type in "Script:" <no
    >quotes> and go to a PSdrive I have mapped on the local file system, just
    >like typing C: or D: would. I wrote this function for my profile:
    >
    >function global:Script: { Set-Location Script: }
    >
    >I modeled after the function in profile.ps1 file in the example directory.
    >Seems pretty simple, I do a dir on the Function drive and it shows up as
    >Script: and looks fine, but if I type Script: I get a function does not
    >exist error. However, if I run type global:Script: it works fine.
    >
    >Any help would be great,
    >
    >Brian JT


      My System SpecsSystem Spec

PSDrive Function problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
new-psdrive Thorsten A. Oeltjen PowerShell 1 22 Mar 2010
New-psdrive in function MiKL PowerShell 2 05 Aug 2009
PSDrive with Credentials Gordon Coulter PowerShell 5 31 Aug 2006
AD as a psdrive Adam Cirillo PowerShell 2 19 Jun 2006
New-PSDrive Suggestion Tom G. PowerShell 5 08 Jun 2006