我可以在不输入“cd”的情况下导航到我的PSDrive吗?

时间:2009-08-26 22:53:00

标签: .net powershell

在Powershell中,我定义了一个名为test的新PSDrive。但是当我在控制台上键入test:时会抛出错误。如果我输入cd test:,它就可以正常工作。

只是输入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

1 个答案:

答案 0 :(得分:5)

你必须定义一个名为“test:”的函数,它调用Set-Location test:,如下所示:

function test: {Set-Location test:}

要查看其他驱动器名称的工作方式,请输入以下命令:

cd function:
dir

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

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