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

Eri*_*ver 1 .net powershell

在Powershell中,我定义了一个名为的新PSDrive test.但是当我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
Run Code Online (Sandbox Code Playgroud)

Joh*_*esH 5

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

function test: {Set-Location test:}
Run Code Online (Sandbox Code Playgroud)

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

cd function:
dir
Run Code Online (Sandbox Code Playgroud)

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

顺便说一下,这个cd命令只是一个别名Set-Location.