Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - PSDrive Function

Reply
 
Old 01-20-2007   #1 (permalink)
BrianJT


 
 

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
Old 01-20-2007   #2 (permalink)
RichS


 
 

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
Old 01-20-2007   #3 (permalink)
Thomas Lee


 
 

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
Old 01-21-2007   #4 (permalink)
Andrew Watt [MVP]


 
 

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
Reply

Thread Tools


Similar Threads
Thread Forum
New-psdrive in function PowerShell
PSDrive with Credentials PowerShell
AD as a psdrive PowerShell
Suggestion: Recycle Bin PSDrive PowerShell
New-PSDrive Suggestion PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46