View Single Post
Old 01-22-2007   #3 (permalink)
Oisin Grehan


 
 

Re: Inconsistent behaviour when using set-location with different providers

The answer is quite simple -- "c:" and "filesystem::c:" are two
different paths. The first is the *name* of a PSDrive (e.g. "C") which
happens to look the same as a windows filesystem root drive , the
second is a provider direct path, which specifies the provider and the
root for said provider. The second is _equivalent_ to the first, but is
not the same powershell path.

- Oisin



Andrew Watt [MVP] wrote:
> Try the following commands. I would be interesed if you can confirm
> the same inconsistencies in behaviour that I show below.
>
> There are three issues that I see:
>
> 1. Why does providing the provider name (or not) in the command affect
> what is displayed in the prompt?
>
> 2. Why is the behaviour of the FileSystem provider and Registry
> provider different? Is the inconsistency a bug?
>
> 3. Why does set-location C: and set-location FileSystem::C: take you
> to different folders? Bug?
>
> PS C:\Documents and Settings\Andrew Watt> set-location HKLM:
> PS HKLM:\> set-location C:
>
> So far so good. But when you provide the name of the provider it
> appears in the prompt.
>
> PS C:\Documents and Settings\Andrew Watt> set-location Registry::HKLM
>
> If you omit the colon with the FileSystem provider you can an error.
>
> PS Microsoft.PowerShell.Core\Registry::HKLM> set-location
> FileSystem::C
> Set-Location : Cannot find path 'C' because it does not exist.
> At line:1 char:13
> + set-location <<<< FileSystem::C
>
> But it works with the colon in place.
>
> PS Microsoft.PowerShell.Core\Registry::HKLM> set-location
> FileSystem::C:
>
> Providing the colon with the Registry provider produces an error (the
> FileSystem equivalent worked).
>
> PS Microsoft.PowerShell.Core\FileSystem::C:\> set-location
> Registry::HKLM:
> Set-Location : Cannot find path 'HKLM:' because it does not exist.
> At line:1 char:13
> + set-location <<<< Registry::HKLM:
>
> For convenience here are the commands with no interpolated comment:
>
> PS C:\Documents and Settings\Andrew Watt> set-location HKLM:
> PS HKLM:\> set-location C:
> PS C:\Documents and Settings\Andrew Watt> set-location Registry::HKLM
> PS Microsoft.PowerShell.Core\Registry::HKLM> set-location
> FileSystem::C
> Set-Location : Cannot find path 'C' because it does not exist.
> At line:1 char:13
> + set-location <<<< FileSystem::C
> PS Microsoft.PowerShell.Core\Registry::HKLM> set-location
> FileSystem::C:
> PS Microsoft.PowerShell.Core\FileSystem::C:\> set-location
> Registry::HKLM:
> Set-Location : Cannot find path 'HKLM:' because it does not exist.
> At line:1 char:13
> + set-location <<<< Registry::HKLM:
> PS Microsoft.PowerShell.Core\FileSystem::C:\> (get-childitem
> functionrompt).definition
> 'PS ' + $(Get-Location) + $(if ($nestedpromptlevel -ge 1) { '>>' }) +
> '> '
> PS Microsoft.PowerShell.Core\FileSystem::C:\>
>
> For information here also is my prompt() function. It's the default.
>
> PS Microsoft.PowerShell.Core\FileSystem::C:\> (get-childitem
> functionrompt).definition
> 'PS ' + $(Get-Location) + $(if ($nestedpromptlevel -ge 1) { '>>' }) +
> '> '
> PS Microsoft.PowerShell.Core\FileSystem::C:\>
>
> Can others confirm the behaviour? Do you see the differences as
> desirable?
>
> Andrew Watt MVP


My System SpecsSystem Spec