2009-08-26 58 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

相關問題