2009-08-26 49 views
1

在Powershell中,我正在定义一个名为test的新PSDrive。但是当我在控制台输入test:时,它会引发错误。如果我输入cd test:它工作正常。我可以在不输入“cd”的情况下导航到我的PSDrive吗?

应该不是我能够浏览到test驱动器只需键入test:

PS> New-PSDrive -name test -psprovider FileSystem -root C:\test 

WARNING: column "CurrentLocation" does not fit into the display and was removed. 

Name   Used (GB)  Free (GB) Provider  Root 
----   ---------  --------- --------  ---- 
test       128.42 FileSystem C:\test 


PS> test: 
The term 'test:' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. 
At line:1 char:6 
    + test: <<<< 
    + CategoryInfo   : ObjectNotFound: (test::String) [], CommandNotFoundException 
    + FullyQualifiedErrorId : CommandNotFoundException 

回答

5

你必须定义一个名为功能“测试:”调用Set-Location test:像这样:

function test: {Set-Location test:} 

一看就知道这也是给其他驱动器名称正在输入以下命令:

cd function: 
dir 

您将看到其他驱动器别名已使用函数映射到其正确的命令。所以C:只是一个函数名称,调用Set-Location C:

顺便说一句,cd命令只是Set-Location的别名。

+0

谢谢! – 2009-08-26 23:33:26

相关问题