![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
| | #3 (permalink) |
| | 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: :\fooMode LastWriteTime Length Name ---- ------------- ------ ---- .... Hope this helps. -- Thomas Lee doctordns@gmail.com MVP - Admin Frameworks and Security |
My System Specs![]() |
| | #4 (permalink) |
| | 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 Specs![]() |
![]() |
| 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 | |||