In Powershell I am defining a new PSDrive called test. But when I type test: at the console it throws an error. If I type cd test: it works fine.
Shouldn’t I be able to navigate to the test drive just by typing 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
You have to define a function called “test:” that calls
Set-Location test:like so:To see that this is also how the other drive names are working enter the following commands:
You will see that the other drive aliases have been mapped to their proper command using a function. So
C:is just a function name that callsSet-Location C:.Btw, the
cdcommand is just an alias forSet-Location.