can't access hkcu

I have PS v4 and am working in Windows 8.1. I have been working in PS ISE as an administrator.

I was doing the chapter 5 lab exercise in “Learning Windows Powershell 3 in a month of lunches” (resetting the property value of Dontprettypath using ‘>set-itemproperty -path advanced -PSPropert Enabledontprettypath -value 1’). For some reason, it was not working.

While checking for what I might have done wrong, I think that I reset the value for HKCU. I was prompted for a value and I typed in ‘cls’.

When I run ‘get-psdrive’, I see hkcu listed.

However, I checking the location gives the following message:
>set-location -path hkcu
set-location : Cannot find path ‘C:hkcu’ because it does not exist.
At line:1, char :1
+set-location -path hkcu
+~~~~~~~~~~~~~~~~~~

  • CategoryInfo : ObjectNotFound: (C:\hkcu:String) [Set-Location], ItemNotFoundException
    +FullyQualifiedErrorId : PathNotFound,MicrosoftPowerShell.Commands.SetLocationCommand

I would appreciate any help you can give.

Thanks

Drive names are followed by a colon.

Cd HKCU:

as a longer explanation for folks who may come across this…

The reason drive names must always be followed by a colon, when the drive name is being used as part of a path, is so that the shell can tell the difference between a drive and a folder.

cd drive

Would try to change to a folder named “drive.”

cd drive:

Changes to a drive named “drive.” The colon is what lets the shell figure out what you’re trying to do.

Thanks. That worked.

Is ‘set-location -path HKCU’ not a valid method of moving to HKCU?

Set-Location is a valid method but you need add a colon to change into the drive.

PS C:\> Set-Location -Path HKCU:
PS HKCU:\>

“cd” is just an alias for Set-Location. Every time you use “cd” the PowerShell engine will invoke Set-Location with the Path parameter.

PS C:\> Get-Alias -Name cd

CommandType     Name
Alias           cd -> Set-Location

Aliases are great for the interactive usage of the PowerShell console because it means less typing. It is very important to get know the aliases because once you get into creating scripts than other PowerShell users except not to see any aliases in your scripts.

Thanks again!